Skip to main content

StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn load_all(&self) -> StorageResult<HashMap<String, StoredEntry>>;
    fn save_all(
        &self,
        entries: &HashMap<String, StoredEntry>,
    ) -> StorageResult<()>;
    fn clear(&self) -> StorageResult<()>;

    // Provided method
    fn is_available(&self) -> bool { ... }
}
Expand description

Trait for pluggable state storage backends.

Implementations must be thread-safe (Send + Sync) to support concurrent access from the registry.

§Implementation Notes

  • load_all should be resilient to partial corruption.
  • save_all should be atomic (write-then-rename pattern for files).
  • clear should remove all stored state for the application.

Required Methods§

Source

fn name(&self) -> &str

Human-readable name for logging.

Source

fn load_all(&self) -> StorageResult<HashMap<String, StoredEntry>>

Load all stored state entries.

Returns an empty map if no state exists (first run). Skips corrupted entries rather than failing entirely.

Source

fn save_all(&self, entries: &HashMap<String, StoredEntry>) -> StorageResult<()>

Save all state entries atomically.

This should replace all existing state (not merge).

Source

fn clear(&self) -> StorageResult<()>

Clear all stored state.

Provided Methods§

Source

fn is_available(&self) -> bool

Check if the backend is available and functional.

Implementors§