Skip to main content

StateStore

Trait StateStore 

Source
pub trait StateStore: Send + Sync {
    type NodeId: Eq + Hash + Clone + Send + Sync;
    type State: Clone + Send + Sync;
    type Error: Send + Sync + 'static;

    // Required methods
    fn get(&self, id: &Self::NodeId) -> Result<Option<Self::State>, Self::Error>;
    fn put(
        &self,
        id: &Self::NodeId,
        state: Self::State,
    ) -> Result<(), Self::Error>;
    fn remove(&self, id: &Self::NodeId) -> Result<(), Self::Error>;
    fn list(&self) -> Result<Vec<(Self::NodeId, Self::State)>, Self::Error>;
}
Expand description

Generic key-value store for per-node runtime state (latency, quotas, counters, etc.).

Strategies read state through trait bounds on node types (e.g., LoadMetric). StateStore is the persistence layer: the library ships InMemoryStore; users can implement this for Redis, etcd, or any other backend.

Required Associated Types§

Source

type NodeId: Eq + Hash + Clone + Send + Sync

Source

type State: Clone + Send + Sync

Source

type Error: Send + Sync + 'static

Required Methods§

Source

fn get(&self, id: &Self::NodeId) -> Result<Option<Self::State>, Self::Error>

Fetch the state for a single node, or None if absent.

Source

fn put(&self, id: &Self::NodeId, state: Self::State) -> Result<(), Self::Error>

Insert or overwrite the state for a node.

Source

fn remove(&self, id: &Self::NodeId) -> Result<(), Self::Error>

Remove the state entry for a node.

Source

fn list(&self) -> Result<Vec<(Self::NodeId, Self::State)>, Self::Error>

Return all stored (id, state) pairs.

Implementors§

Source§

impl<Id, State> StateStore for InMemoryStore<Id, State>
where Id: Eq + Hash + Clone + Send + Sync, State: Clone + Send + Sync,