pub trait StorageBackend: Send + Sync {
// Required methods
fn append(&mut self, data: &[u8]) -> Result<(), PersistenceError>;
fn read(&self) -> Result<Vec<u8>, PersistenceError>;
fn atomic_write(
&self,
key: &str,
data: &[u8],
) -> Result<(), PersistenceError>;
}Expand description
Abstraction for persistent storage backend.
Enables swappable backends for File (native) and IndexedDB (WASM).
Required Methods§
Sourcefn append(&mut self, data: &[u8]) -> Result<(), PersistenceError>
fn append(&mut self, data: &[u8]) -> Result<(), PersistenceError>
Appends data to the end of the storage.
Used for Write-Ahead Log (WAL) operations.
§Errors
Returns PersistenceError::Io if writing fails.
Sourcefn read(&self) -> Result<Vec<u8>, PersistenceError>
fn read(&self) -> Result<Vec<u8>, PersistenceError>
Reads the entire storage content.
Used for recovery/replay.
§Errors
Returns PersistenceError::Io if reading fails.
Sourcefn atomic_write(&self, key: &str, data: &[u8]) -> Result<(), PersistenceError>
fn atomic_write(&self, key: &str, data: &[u8]) -> Result<(), PersistenceError>
Atomically writes the provided bytes identified by key.
Implementations should ensure that either the previous value remains
intact or the new value is fully committed. Backends that represent a
single file may choose to ignore key and always operate on their
configured path.
§Errors
Returns PersistenceError::Io if writing or renaming fails.