Skip to main content

StorageBackend

Trait StorageBackend 

Source
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§

Source

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.

Source

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.
Source

fn delete(&self, key: &str) -> Result<(), BackendError>

Remove a setting from the database.

§Arguments
  • key (&str): The identifier of the setting to delete.

Provided Methods§

Source

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".

Implementors§