Skip to main content

StorageDriver

Trait StorageDriver 

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

Source

fn capabilities(&self) -> DriverCapabilities

Backend capability flags (kind, zone-append, snapshot cost, CSD dispatch, max concurrent writers).

Source

fn write(&self, key: &str, data: &[u8]) -> Result<(), StorageError>

Store data under key, replacing any existing value.

Source

fn append(&self, key: &str, data: &[u8]) -> Result<(), StorageError>

Append data to the value under key (created if absent).

Source

fn read(&self, key: &str) -> Result<Vec<u8>, StorageError>

Read the full value under key; NotFound when absent.

Source

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.

Source

fn delete(&self, key: &str) -> Result<(), StorageError>

Remove key; idempotent — deleting an absent key is Ok.

Source

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.

Source

fn flush(&self) -> Result<(), StorageError>

Durability barrier — flush driver-level buffering to stable storage (no-op for write-through backends).

Source

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.

Source

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.

Source

fn describe(&self) -> &str

One-line backend description for diagnostics.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§