pub trait StorageBackend: Send + Sync {
// Required methods
fn load_all(&self) -> Result<HashMap<String, StoredValue>, BackendError>;
fn set(&self, key: &str, value: &StoredValue) -> Result<(), BackendError>;
fn delete(&self, key: &str) -> Result<(), BackendError>;
// Provided method
fn watch_changes(&self) -> Option<Receiver<()>> { ... }
}Required Methods§
Sourcefn load_all(&self) -> Result<HashMap<String, StoredValue>, BackendError>
fn load_all(&self) -> Result<HashMap<String, StoredValue>, BackendError>
Load all persisted settings into memory. This method is called at load and on watcher ticks.
Sourcefn set(&self, key: &str, value: &StoredValue) -> Result<(), BackendError>
fn set(&self, key: &str, value: &StoredValue) -> Result<(), BackendError>
Persist a setting to the database.
§Arguments
- key (&str): The identifier of the setting to persist.
- value (&StoredValue): The value associated with the setting’s identifier.
Provided Methods§
Sourcefn watch_changes(&self) -> Option<Receiver<()>>
fn watch_changes(&self) -> Option<Receiver<()>>
Subscribe to the backend storage event stream. Default returns None.
The returned receiver fires for every change, including own-process writes.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".