pub trait PersistedStore<K: PersistedKey> {
// Required methods
fn load_persisted(key: &K) -> Option<K::Value>;
fn store_persisted(key: &K, value: &K::Value);
}Expand description
A trait for any data store capable of persisting data. A store is the layer
that saves data. It could save it in memory, on disk, over the network, etc.
The generic parameter K defines which keys this store is capable of
saving. For example, if your storage mechanism involves stringifyin keys,
your implementation may look like:
struct Store;
impl<K: PersistedKey + Display> for Store {
...
}This trait enforces three key requirements on all implementors:
- It is statically accessible, i.e. you can load and store data without a reference to the store
- It does not return errors. This does not mean it is infallible; it just means that if errors can occur during load/store, they are handled within the implementation rather than propagated. For example, they could be logged for debugging.
- Its is synchronous.
asyncload and store operations are not supported.
All three of these requirements derive from how the store is accessed.
Values are loaded during initialization by Persisted/PersistedLazy, and
saved by their respective guard’s Drop implementations. In both cases,
there is no reference to the store available, and no way of propagating
errors or futures. For this reason, your store access should be fast, to
prevent latency in your program.
Required Methods§
Sourcefn load_persisted(key: &K) -> Option<K::Value>
fn load_persisted(key: &K) -> Option<K::Value>
Load a persisted value from the store, identified by the given key.
Return Ok(None) if the value isn’t present.
Sourcefn store_persisted(key: &K, value: &K::Value)
fn store_persisted(key: &K, value: &K::Value)
Persist a value in the store, under the given key
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.