Skip to main content

StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend: Send + Sync {
    // Required methods
    fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
    fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;
    fn remove(&self, key: &[u8]) -> Result<()>;
    fn prefix_scan(&self, prefix: &[u8]) -> Result<Vec<(Vec<u8>, Vec<u8>)>>;
    fn prefix_count(&self, prefix: &[u8]) -> Result<usize>;
    fn prefix_scan_keys(&self, prefix: &[u8]) -> Result<Vec<Vec<u8>>>;
    fn prefix_scan_batch(
        &self,
        prefix: &[u8],
        batch_size: usize,
        after_key: Option<&[u8]>,
    ) -> Result<Vec<(Vec<u8>, Vec<u8>)>>;
    fn range_scan(
        &self,
        start: &[u8],
        end: &[u8],
    ) -> Result<Vec<(Vec<u8>, Vec<u8>)>>;
    fn batch(&self) -> Box<dyn BatchOperations>;
    fn flush(&self) -> Result<()>;
}
Expand description

Storage backend trait for key-value operations.

Required Methods§

Source

fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>

Gets a value by key.

§Errors

Returns an error if the storage operation fails.

Source

fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>

Inserts a key-value pair.

§Errors

Returns an error if the storage operation fails.

Source

fn remove(&self, key: &[u8]) -> Result<()>

Removes a key.

§Errors

Returns an error if the storage operation fails.

Source

fn prefix_scan(&self, prefix: &[u8]) -> Result<Vec<(Vec<u8>, Vec<u8>)>>

Scans all keys with the given prefix.

§Errors

Returns an error if the storage operation fails.

Source

fn prefix_count(&self, prefix: &[u8]) -> Result<usize>

Counts entries matching the given prefix without materializing values.

§Errors

Returns an error if the storage operation fails.

Source

fn prefix_scan_keys(&self, prefix: &[u8]) -> Result<Vec<Vec<u8>>>

Returns only keys matching the given prefix, without loading values.

§Errors

Returns an error if the storage operation fails.

Source

fn prefix_scan_batch( &self, prefix: &[u8], batch_size: usize, after_key: Option<&[u8]>, ) -> Result<Vec<(Vec<u8>, Vec<u8>)>>

Scans entries matching prefix in batches, starting after after_key.

Returns at most batch_size entries. Pass None for after_key to start from the beginning of the prefix range.

§Errors

Returns an error if the storage operation fails.

Source

fn range_scan( &self, start: &[u8], end: &[u8], ) -> Result<Vec<(Vec<u8>, Vec<u8>)>>

Scans keys in the given range.

§Errors

Returns an error if the storage operation fails.

Source

fn batch(&self) -> Box<dyn BatchOperations>

Creates a new batch for atomic operations.

Source

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

Flushes pending writes to storage.

§Errors

Returns an error if the flush operation fails.

Implementors§