57 lines
2.4 KiB
Rust
57 lines
2.4 KiB
Rust
//! # `lib_efo`
|
||
//!
|
||
//! The **engine** that drives *Epoch Forge*. It contains a pure, representation of a fantasy world and all the logic needed to manipulate it.
|
||
//!
|
||
//! The crate is split into the following domains, each exposed as a public module:
|
||
//! - TODO[1]: `world` – holds the global state (`World`) and a lightweight snapshot (`Context`).
|
||
//! - TODO[0]: `epoch` – manages the passage of time and epoch switching.
|
||
//! - TODO[1]: `event` – CRUD and evaluation of events that affect the world.
|
||
//! - TODO[4]: `org` – organisations, guilds, factions and their history.
|
||
//! - TODO[2]: `character` – individual characters, traits and lineage.
|
||
//! - TODO[1]: `town` – towns, cities, trade hubs and their populations.
|
||
//! - TODO[2]: `link` – relations such as wars, alliances, roads, commerce.
|
||
//! - TODO[3]: `storage` – generic persistence layer (`Store<T>`) with JSON/YAML back‑ends.
|
||
//! - TODO[4]: `util` – small helpers, ID generation, error types, etc.
|
||
//!
|
||
//! All public types implement `serde::Serialize / Deserialize` so that they can
|
||
//! be persisted easily. The `World` struct also offers a convenient
|
||
//! `World::load()` / `World::save()` API that uses the default JSON file
|
||
|
||
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
||
#![deny(clippy::unwrap_used)]
|
||
|
||
#[macro_use]
|
||
pub mod error;
|
||
pub mod entity;
|
||
pub mod epoch;
|
||
pub mod stats;
|
||
pub mod utils;
|
||
|
||
use std::io::Result as IoResult;
|
||
|
||
/// Marker trait for anything that can be persisted via the `Store<T>` abstraction.
|
||
///
|
||
/// It is a thin wrapper around `serde::Serialize` and `serde::de::DeserializeOwned` so that the
|
||
/// compiler can infer that the type is both serialisable *and* deserialisable.
|
||
pub trait Persistable: serde::Serialize + serde::de::DeserializeOwned {}
|
||
impl<T> Persistable for T where T: serde::Serialize + serde::de::DeserializeOwned + 'static {}
|
||
|
||
/// The generic store. All domain entities that need persistence should use this trait.
|
||
/// It can be backed by a file, a DB, an HTTP API, … as long as it knows how to read/write the type `T`.
|
||
pub trait Store<T>
|
||
where
|
||
T: Persistable,
|
||
{
|
||
/// Read a value identified by `id`.
|
||
fn read(&self, id: &str) -> IoResult<Option<T>>;
|
||
|
||
/// Write (or overwrite) a value identified by `id`.
|
||
fn write(&self, id: &str, value: &T) -> IoResult<()>;
|
||
|
||
/// Delete the value identified by `id`.
|
||
fn delete(&self, id: &str) -> IoResult<()>;
|
||
|
||
/// List all ids known to this store.
|
||
fn list_ids(&self) -> IoResult<Vec<String>>;
|
||
}
|