//! # `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: `world` – holds the global state (`World`) and a lightweight snapshot (`Context`). //! - TODO: `epoch` – manages the passage of time and epoch switching. //! - TODO: `event` – CRUD and evaluation of events that affect the world. //! - TODO: `org` – organisations, guilds, factions and their history. //! - TODO: `character` – individual characters, traits and lineage. //! - TODO: `town` – towns, cities, trade hubs and their populations. //! - TODO: `link` – relations such as wars, alliances, roads, commerce. //! - TODO: `storage` – generic persistence layer (`Store`) with JSON/YAML back‑ends. //! - TODO: `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 pub mod epoch_struct; #[macro_use] pub mod error; pub mod utils; use std::io::Result as IoResult; /// Marker trait for anything that can be persisted via the `Store` 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 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 where T: Persistable, { /// Read a value identified by `id`. fn read(&self, id: &str) -> IoResult>; /// 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>; }