pub trait StorageBackend: Send + Sync {
// Required methods
fn put(&mut self, key: &[u8], value: &[u8]) -> Result<()>;
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
fn delete(&mut self, key: &[u8]) -> Result<()>;
fn exists(&self, key: &[u8]) -> Result<bool>;
fn scan_prefix(&self, prefix: &[u8]) -> Result<Vec<KeyValue>>;
fn write_batch(&mut self, operations: Vec<BatchOperation>) -> Result<()>;
fn flush(&mut self) -> Result<()>;
}Expand description
Trait defining the storage backend interface.
All storage operations are explicit and return Result to handle failures.
Implementations must ensure crash-safety and atomic batch operations.
Required Methods§
Sourcefn put(&mut self, key: &[u8], value: &[u8]) -> Result<()>
fn put(&mut self, key: &[u8], value: &[u8]) -> Result<()>
Store a key-value pair.
This operation is durable immediately (no deferred writes).
§Errors
Returns an error if the write fails.
Sourcefn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>
Retrieve a value by key.
§Errors
Returns an error if the read fails.
Returns Ok(None) if the key doesn’t exist.
Sourcefn delete(&mut self, key: &[u8]) -> Result<()>
fn delete(&mut self, key: &[u8]) -> Result<()>
Delete a key-value pair.
§Errors
Returns an error if the delete fails. Does not error if the key doesn’t exist (idempotent).
Sourcefn scan_prefix(&self, prefix: &[u8]) -> Result<Vec<KeyValue>>
fn scan_prefix(&self, prefix: &[u8]) -> Result<Vec<KeyValue>>
Iterate over all key-value pairs with keys starting with the given prefix.
Returns an iterator over matching pairs.
§Errors
Returns an error if iteration setup fails.
Sourcefn write_batch(&mut self, operations: Vec<BatchOperation>) -> Result<()>
fn write_batch(&mut self, operations: Vec<BatchOperation>) -> Result<()>
Execute a batch of write operations atomically.
Either all operations succeed or none do.
§Errors
Returns an error if any operation in the batch fails.