pub trait StateMgr: Clone {
    fn load<D>(&self, key: &str) -> Result<Option<D>, Error>
    where
        D: DeserializeOwned
; fn store<S>(&self, key: &str, val: &S) -> Result<(), Error>
    where
        S: Serialize
; fn can_store(&self) -> bool; fn try_lock(&self) -> Result<LockStatus, Error>; fn unlock(&self) -> Result<(), Error>; fn create_handle<T>(self, key: impl Into<String>) -> DynStorageHandle<T>
    where
        Self: Send + Sync + Sized + 'static,
        T: Serialize + DeserializeOwned + 'static
, { ... } }
Expand description

An object that can manage persistent state.

State is implemented as a simple key-value store, where the values are objects that can be serialized and deserialized.

Warnings

Current implementations may place additional limits on the types of objects that can be stored. This is not a great example of OO design: eventually we should probably clarify that more.

Required Methods

Try to load the object with key key from the store.

Return None if no such object exists.

Try to save val with key key in the store.

Replaces any previous value associated with key.

Return true if this is a read-write state manager.

If it returns false, then attempts to store will fail with Error::NoLock

Try to become a read-write state manager if possible, without blocking.

This function will return an error only if something really unexpected went wrong. It may return Ok(_) even if we don’t acquire the lock: check the return value or call [StateMgr::can_store()] to see if the lock is held.

Release any locks held and become a read-only state manager again. If no locks were held, do nothing.

Provided Methods

Make a new StorageHandle to store values of particular type at a particular key.

Implementors