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§
Sourcefn open(path: &Path) -> StorageResult<Self>where
Self: Sized,
fn open(path: &Path) -> StorageResult<Self>where
Self: Sized,
Open or create a storage instance at the given path.
Sourcefn delete(&self, key: &[u8]) -> StorageResult<()>
fn delete(&self, key: &[u8]) -> StorageResult<()>
Delete a key.
Sourcefn flush(&self) -> StorageResult<()>
fn flush(&self) -> StorageResult<()>
Flush pending writes to disk.
Sourcefn scan_prefix(&self, prefix: &[u8]) -> StorageResult<Vec<(Vec<u8>, Vec<u8>)>>
fn scan_prefix(&self, prefix: &[u8]) -> StorageResult<Vec<(Vec<u8>, Vec<u8>)>>
Iterate over all keys with a given prefix.
Sourcefn clear(&self) -> StorageResult<()>
fn clear(&self) -> StorageResult<()>
Clear all data (use with caution).
Provided Methods§
Sourcefn contains(&self, key: &[u8]) -> StorageResult<bool>
fn contains(&self, key: &[u8]) -> StorageResult<bool>
Check if a key exists.