pub trait StorageBackend: Send + Sync {
// Required methods
fn insert(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>;
fn get(&self, table: &str, key: &[u8]) -> DbxResult<Option<Vec<u8>>>;
fn delete(&self, table: &str, key: &[u8]) -> DbxResult<bool>;
fn scan<R: RangeBounds<Vec<u8>> + Clone>(
&self,
table: &str,
range: R,
) -> DbxResult<Vec<(Vec<u8>, Vec<u8>)>>;
fn scan_one<R: RangeBounds<Vec<u8>> + Clone>(
&self,
table: &str,
range: R,
) -> DbxResult<Option<(Vec<u8>, Vec<u8>)>>;
fn flush(&self) -> DbxResult<()>;
fn count(&self, table: &str) -> DbxResult<usize>;
fn table_names(&self) -> DbxResult<Vec<String>>;
// Provided method
fn insert_batch(
&self,
table: &str,
rows: Vec<(Vec<u8>, Vec<u8>)>,
) -> DbxResult<()> { ... }
}Expand description
Core storage interface — all tiers implement this trait.
§Design Principles
- DIP: SQL layer depends on this trait, never on concrete types.
- Strategy: New storage tiers are added by implementing this trait.
- Thread Safety:
Send + Syncrequired for concurrent access.
§Contract
insert: Upsert semantics — overwrites existing key.get: ReturnsNonefor non-existent keys, never errors.delete: Returnstrueif key existed,falseotherwise.scan: Returns key-value pairs in key order within range.flush: Persists buffered data to durable storage.count: Returns the number of keys in a table.table_names: Returns all table names.
Required Methods§
Sourcefn insert(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>
fn insert(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>
Insert a key-value pair.
Sourcefn scan<R: RangeBounds<Vec<u8>> + Clone>(
&self,
table: &str,
range: R,
) -> DbxResult<Vec<(Vec<u8>, Vec<u8>)>>
fn scan<R: RangeBounds<Vec<u8>> + Clone>( &self, table: &str, range: R, ) -> DbxResult<Vec<(Vec<u8>, Vec<u8>)>>
Scan a range of keys.
Sourcefn scan_one<R: RangeBounds<Vec<u8>> + Clone>(
&self,
table: &str,
range: R,
) -> DbxResult<Option<(Vec<u8>, Vec<u8>)>>
fn scan_one<R: RangeBounds<Vec<u8>> + Clone>( &self, table: &str, range: R, ) -> DbxResult<Option<(Vec<u8>, Vec<u8>)>>
Scan a single key-value pair in a range (optimized).
Sourcefn table_names(&self) -> DbxResult<Vec<String>>
fn table_names(&self) -> DbxResult<Vec<String>>
Return all table names managed by this backend.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.