pub trait StorageDriver: Send + Sync {
// Required methods
fn capabilities(&self) -> DriverCapabilities;
fn write(&self, key: &str, data: &[u8]) -> Result<(), StorageError>;
fn append(&self, key: &str, data: &[u8]) -> Result<(), StorageError>;
fn read(&self, key: &str) -> Result<Vec<u8>, StorageError>;
fn read_range(
&self,
key: &str,
offset: usize,
len: usize,
) -> Result<Vec<u8>, StorageError>;
fn delete(&self, key: &str) -> Result<(), StorageError>;
fn snapshot(&self, snapshot_id: &str) -> Result<(), StorageError>;
fn flush(&self) -> Result<(), StorageError>;
fn prefetch_hint(&self, key: &str);
fn eviction_hint(&self, key: &str);
fn describe(&self) -> &str;
}Expand description
Key/value storage backend contract — flat key → bytes semantics
with snapshot and cache-hint hooks. Implementations range from the
portable MmapDriver through APFS/ZNS/NVMe-passthrough variants;
callers pick by capabilities().
Required Methods§
Sourcefn capabilities(&self) -> DriverCapabilities
fn capabilities(&self) -> DriverCapabilities
Backend capability flags (kind, zone-append, snapshot cost, CSD dispatch, max concurrent writers).
Sourcefn write(&self, key: &str, data: &[u8]) -> Result<(), StorageError>
fn write(&self, key: &str, data: &[u8]) -> Result<(), StorageError>
Store data under key, replacing any existing value.
Sourcefn append(&self, key: &str, data: &[u8]) -> Result<(), StorageError>
fn append(&self, key: &str, data: &[u8]) -> Result<(), StorageError>
Append data to the value under key (created if absent).
Sourcefn read(&self, key: &str) -> Result<Vec<u8>, StorageError>
fn read(&self, key: &str) -> Result<Vec<u8>, StorageError>
Read the full value under key; NotFound when absent.
Sourcefn read_range(
&self,
key: &str,
offset: usize,
len: usize,
) -> Result<Vec<u8>, StorageError>
fn read_range( &self, key: &str, offset: usize, len: usize, ) -> Result<Vec<u8>, StorageError>
Read len bytes starting at offset within the value under
key; result is truncated at the value end, Err when
offset is past it.
Sourcefn delete(&self, key: &str) -> Result<(), StorageError>
fn delete(&self, key: &str) -> Result<(), StorageError>
Remove key; idempotent — deleting an absent key is Ok.
Sourcefn snapshot(&self, snapshot_id: &str) -> Result<(), StorageError>
fn snapshot(&self, snapshot_id: &str) -> Result<(), StorageError>
Create a point-in-time snapshot named snapshot_id.
On APFS this calls clonefile(2) and is O(1), zero-cost on disk.
Sourcefn flush(&self) -> Result<(), StorageError>
fn flush(&self) -> Result<(), StorageError>
Durability barrier — flush driver-level buffering to stable storage (no-op for write-through backends).
Sourcefn prefetch_hint(&self, key: &str)
fn prefetch_hint(&self, key: &str)
Advisory hint that key will be read soon (e.g. MADV_WILLNEED
on Darwin); free to be a no-op.
Sourcefn eviction_hint(&self, key: &str)
fn eviction_hint(&self, key: &str)
Advisory hint that key’s pages may be reclaimed (e.g.
MADV_FREE on Darwin); free to be a no-op.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".