StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend: Send + Sync {
Show 14 methods // Required methods fn put(&mut self, key: &[u8], item: &DbItem) -> Result<()>; fn get(&self, key: &[u8]) -> Result<Option<DbItem>>; fn delete(&mut self, key: &[u8]) -> Result<Option<DbItem>>; fn contains_key(&self, key: &[u8]) -> Result<bool>; fn keys_with_prefix(&self, prefix: &[u8]) -> Result<Vec<Bytes>>; fn scan_prefix(&self, prefix: &[u8]) -> Result<BTreeMap<Bytes, DbItem>>; fn len(&self) -> Result<usize>; fn is_empty(&self) -> Result<bool>; fn sync(&mut self) -> Result<()>; fn close(&mut self) -> Result<()>; fn stats(&self) -> Result<StorageStats>; fn batch(&mut self, ops: &[StorageOp]) -> Result<()>; fn iter(&self) -> Result<Box<dyn Iterator<Item = (Bytes, DbItem)> + '_>>; fn cleanup_expired(&mut self, now: SystemTime) -> Result<usize>;
}
Expand description

Trait for storage backend implementations

This trait abstracts the storage layer, allowing for different backends such as in-memory, persistent file-based storage, or external databases.

Required Methods§

Source

fn put(&mut self, key: &[u8], item: &DbItem) -> Result<()>

Insert or update a key-value pair

Source

fn get(&self, key: &[u8]) -> Result<Option<DbItem>>

Get a value by key

Source

fn delete(&mut self, key: &[u8]) -> Result<Option<DbItem>>

Delete a key and return the old value if it existed

Source

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

Check if a key exists

Source

fn keys_with_prefix(&self, prefix: &[u8]) -> Result<Vec<Bytes>>

Get all keys with a given prefix

Source

fn scan_prefix(&self, prefix: &[u8]) -> Result<BTreeMap<Bytes, DbItem>>

Returns all key-value pairs with keys matching the given prefix.

Source

fn len(&self) -> Result<usize>

Get the total number of keys

Source

fn is_empty(&self) -> Result<bool>

Check if the storage is empty

Source

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

Flush any pending writes to persistent storage

Source

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

Close the storage backend

Source

fn stats(&self) -> Result<StorageStats>

Get storage statistics

Source

fn batch(&mut self, ops: &[StorageOp]) -> Result<()>

Batch operation support

Source

fn iter(&self) -> Result<Box<dyn Iterator<Item = (Bytes, DbItem)> + '_>>

Iterator over all key-value pairs

Source

fn cleanup_expired(&mut self, now: SystemTime) -> Result<usize>

Cleanup expired items (for TTL support)

Implementors§