| Crates.io | states |
| lib.rs | states |
| version | 0.1.1 |
| created_at | 2025-11-12 13:42:52.772762+00 |
| updated_at | 2025-11-12 13:59:19.97751+00 |
| description | A lightweight, type-safe registry for managing cached and self-initializing states. |
| homepage | https://github.com/WolverinDEV/states-rs |
| repository | |
| max_upload_size | |
| id | 1929376 |
| size | 64,573 |
A lightweight, type-safe registry for managing cached and self-initializing.
states lets you define reusable, parameterized objects that can be lazily created,
cached, and invalidated — ideal for dependency-aware systems or runtime caching.
Note:
The crate isno_stdcompatible by default and does not use the standard library.
use states::{State, StateRegistry, StateType};
struct Double(u64);
impl State for Double {
type Error = std::convert::Infallible;
type Parameter<'a> = u64;
fn create(_: &StateRegistry, param: Self::Parameter<'_>) -> Result<Self, Self::Error> {
Ok(Self(param * 2))
}
fn state_type(&self) -> StateType {
StateType::Persistent
}
}
fn main() {
let registry = StateRegistry::new(0x10);
let state = registry.resolve_with::<Double>(21).unwrap();
assert_eq!(state.0, 42);
}
[dependencies]
states = "0.1"