StorageBackend

Trait StorageBackend 

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

Source

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.

Source

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.

Source

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

Source

fn exists(&self, key: &[u8]) -> Result<bool>

Check if a key exists.

§Errors

Returns an error if the check fails.

Source

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.

Source

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.

Source

fn flush(&mut self) -> Result<()>

Flush any buffered writes to disk.

This is explicit - no automatic flushing happens.

§Errors

Returns an error if flush fails.

Implementors§