states

Crates.iostates
lib.rsstates
version0.1.1
created_at2025-11-12 13:42:52.772762+00
updated_at2025-11-12 13:59:19.97751+00
descriptionA lightweight, type-safe registry for managing cached and self-initializing states.
homepagehttps://github.com/WolverinDEV/states-rs
repository
max_upload_size
id1929376
size64,573
(WolverinDEV)

documentation

README

states-rs   Latest Version License: GPL v3 GitHub build status

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 is no_std compatible by default and does not use the standard library.

Example

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);
}

Features

  • Lazy creation and automatic caching
  • Type-safe lookup by (TypeId, Parameter)
  • Persistent and volatile caching policies
  • Dependency-aware design

Installation

[dependencies]
states = "0.1"
Commit count: 0

cargo fmt