pub trait StorageBackend:
Debug
+ Send
+ Sync {
Show 13 methods
// Required methods
fn get(&self, key: &str) -> Result<Option<Vec<u8>>>;
fn put(&self, key: &str, value: &[u8]) -> Result<()>;
fn delete(&self, key: &str) -> Result<bool>;
fn exists(&self, key: &str) -> Result<bool>;
fn keys(&self) -> Result<Vec<String>>;
fn len(&self) -> Result<usize>;
fn clear(&self) -> Result<()>;
fn backend_name(&self) -> &'static str;
// Provided methods
fn is_empty(&self) -> Result<bool> { ... }
fn batch_get(&self, keys: &[&str]) -> Result<Vec<Option<Vec<u8>>>> { ... }
fn batch_put(&self, items: &[(&str, &[u8])]) -> Result<()> { ... }
fn batch_delete(&self, keys: &[&str]) -> Result<usize> { ... }
fn stats(&self) -> StorageStats { ... }
}Expand description
Storage backend trait for abstracting different storage systems.
This trait provides a simple key-value interface for document storage. Implementations can use different underlying storage systems:
- File system
- In-memory (for testing)
- Database (SQLite, RocksDB, etc.)
- Cloud storage (S3, etc.)
§Thread Safety
All implementations must be Send + Sync to support concurrent access.
Required Methods§
Sourcefn get(&self, key: &str) -> Result<Option<Vec<u8>>>
fn get(&self, key: &str) -> Result<Option<Vec<u8>>>
Get a value by key.
Returns None if the key doesn’t exist.
Sourcefn put(&self, key: &str, value: &[u8]) -> Result<()>
fn put(&self, key: &str, value: &[u8]) -> Result<()>
Store a value with the given key.
Overwrites any existing value.
Sourcefn delete(&self, key: &str) -> Result<bool>
fn delete(&self, key: &str) -> Result<bool>
Delete a value by key.
Returns true if the value was deleted, false if it didn’t exist.
Sourcefn backend_name(&self) -> &'static str
fn backend_name(&self) -> &'static str
Get storage backend name.
Provided Methods§
Sourcefn batch_get(&self, keys: &[&str]) -> Result<Vec<Option<Vec<u8>>>>
fn batch_get(&self, keys: &[&str]) -> Result<Vec<Option<Vec<u8>>>>
Get multiple values by keys.
Returns a vector of options, one for each key.
Sourcefn batch_put(&self, items: &[(&str, &[u8])]) -> Result<()>
fn batch_put(&self, items: &[(&str, &[u8])]) -> Result<()>
Store multiple key-value pairs.
Default implementation calls put for each item.
Sourcefn batch_delete(&self, keys: &[&str]) -> Result<usize>
fn batch_delete(&self, keys: &[&str]) -> Result<usize>
Delete multiple keys.
Returns the number of keys that were actually deleted.