Skip to main content

IndexBackend

Trait IndexBackend 

Source
pub trait IndexBackend: Send + Sync {
    // Required methods
    fn put(&self, key: &str, value: &[u8]) -> Result<(), IndexError>;
    fn get(&self, key: &str) -> Result<Option<Vec<u8>>, IndexError>;
    fn delete(&self, key: &str) -> Result<(), IndexError>;
    fn batch_put(
        &self,
        entries: Vec<(String, Vec<u8>)>,
    ) -> Result<(), IndexError>;
    fn scan(
        &self,
        visitor: &mut dyn FnMut(&[u8]) -> Result<(), IndexError>,
    ) -> Result<(), IndexError>;

    // Provided method
    fn flush(&self) -> Result<(), IndexError> { ... }
}
Expand description

Trait for a key-value storage backend for the index. This allows for different storage implementations (e.g., in-memory, Redb).

Required Methods§

Source

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

Insert or update a key-value pair.

Source

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

Retrieve a value by key.

Source

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

Delete a key-value pair.

Source

fn batch_put(&self, entries: Vec<(String, Vec<u8>)>) -> Result<(), IndexError>

Insert or update multiple key-value pairs in a batch.

Source

fn scan( &self, visitor: &mut dyn FnMut(&[u8]) -> Result<(), IndexError>, ) -> Result<(), IndexError>

Scan all values in the backend, calling the visitor for each one.

Provided Methods§

Source

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

Flush any buffered writes to the backend.

Implementors§