Skip to main content

StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend: Send + Sync {
    // Required methods
    fn open(path: &Path) -> StorageResult<Self>
       where Self: Sized;
    fn get(&self, key: &[u8]) -> StorageResult<Option<Vec<u8>>>;
    fn set(&self, key: &[u8], value: &[u8]) -> StorageResult<()>;
    fn delete(&self, key: &[u8]) -> StorageResult<()>;
    fn flush(&self) -> StorageResult<()>;
    fn scan_prefix(
        &self,
        prefix: &[u8],
    ) -> StorageResult<Vec<(Vec<u8>, Vec<u8>)>>;
    fn clear(&self) -> StorageResult<()>;

    // Provided method
    fn contains(&self, key: &[u8]) -> StorageResult<bool> { ... }
}
Expand description

Abstraction over key-value storage backends.

This trait allows rpytest to use different storage implementations (e.g., sled, redb) without changing the core logic.

Required Methods§

Source

fn open(path: &Path) -> StorageResult<Self>
where Self: Sized,

Open or create a storage instance at the given path.

Source

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

Get a value by key.

Source

fn set(&self, key: &[u8], value: &[u8]) -> StorageResult<()>

Set a key-value pair.

Source

fn delete(&self, key: &[u8]) -> StorageResult<()>

Delete a key.

Source

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

Flush pending writes to disk.

Source

fn scan_prefix(&self, prefix: &[u8]) -> StorageResult<Vec<(Vec<u8>, Vec<u8>)>>

Iterate over all keys with a given prefix.

Source

fn clear(&self) -> StorageResult<()>

Clear all data (use with caution).

Provided Methods§

Source

fn contains(&self, key: &[u8]) -> StorageResult<bool>

Check if a key exists.

Implementors§