epoch_forge/lib_efo/src/lib.rs

55 lines
2.4 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! # `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)]
pub mod epoch_struct;
pub mod epoch_traits;
#[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<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>>;
}