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§
Sourcefn delete(&mut self, key: &[u8]) -> Result<Option<DbItem>>
fn delete(&mut self, key: &[u8]) -> Result<Option<DbItem>>
Delete a key and return the old value if it existed
Sourcefn contains_key(&self, key: &[u8]) -> Result<bool>
fn contains_key(&self, key: &[u8]) -> Result<bool>
Check if a key exists
Sourcefn keys_with_prefix(&self, prefix: &[u8]) -> Result<Vec<Bytes>>
fn keys_with_prefix(&self, prefix: &[u8]) -> Result<Vec<Bytes>>
Get all keys with a given prefix
Sourcefn scan_prefix(&self, prefix: &[u8]) -> Result<BTreeMap<Bytes, DbItem>>
fn scan_prefix(&self, prefix: &[u8]) -> Result<BTreeMap<Bytes, DbItem>>
Returns all key-value pairs with keys matching the given prefix.
Sourcefn stats(&self) -> Result<StorageStats>
fn stats(&self) -> Result<StorageStats>
Get storage statistics
Sourcefn iter(&self) -> Result<Box<dyn Iterator<Item = (Bytes, DbItem)> + '_>>
fn iter(&self) -> Result<Box<dyn Iterator<Item = (Bytes, DbItem)> + '_>>
Iterator over all key-value pairs
Sourcefn cleanup_expired(&mut self, now: SystemTime) -> Result<usize>
fn cleanup_expired(&mut self, now: SystemTime) -> Result<usize>
Cleanup expired items (for TTL support)