Skip to main content

StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn read(&self, key: &str) -> Result<Option<Vec<u8>>, StorageError>;
    fn write(&self, key: &str, bytes: &[u8]) -> Result<(), StorageError>;

    // Provided methods
    fn delete(&self, key: &str) -> Result<(), StorageError> { ... }
    fn list(&self, prefix: &str) -> Result<Vec<String>, StorageError> { ... }
    fn flush(&self) -> Result<(), StorageError> { ... }
}
Expand description

Bytes-level kv backend. Tiers layer typed serialization on top via Codec.

Required Methods§

Source

fn name(&self) -> &str

Diagnostic name (e.g. "memory", "file:./checkpoints"). Surfaces in error messages and tier Display impls.

Source

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

Read raw bytes; returns Ok(None) on miss.

Source

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

Write raw bytes.

Provided Methods§

Source

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

Optional delete-by-key. Default is no-op so append-only or read-only backends can stay quiet.

Source

fn list(&self, prefix: &str) -> Result<Vec<String>, StorageError>

Enumerate keys matching prefix (lex-ASC). Empty prefix enumerates all keys. Default returns BackendNoListSupport — backends that don’t support enumeration surface the diagnostic here at first call, NOT at attach (mirrors TS lazy-throw semantics for list_by_prefix).

Source

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

Optional drain hook — adapter authors implement when buffering writes. Default no-op; tier flush() does NOT cascade into this by default (the tier owns its own buffer; backend buffering is a separate concern the backend author opts into).

Implementors§