redb

Trait StorageBackend

Source
pub trait StorageBackend:
    'static
    + Debug
    + Send
    + Sync {
    // Required methods
    fn len(&self) -> Result<u64, Error>;
    fn read(&self, offset: u64, len: usize) -> Result<Vec<u8>, Error>;
    fn set_len(&self, len: u64) -> Result<(), Error>;
    fn sync_data(&self, eventual: bool) -> Result<(), Error>;
    fn write(&self, offset: u64, data: &[u8]) -> Result<(), Error>;
}
Expand description

Implements persistent storage for a database.

Required Methods§

Source

fn len(&self) -> Result<u64, Error>

Gets the current length of the storage.

Source

fn read(&self, offset: u64, len: usize) -> Result<Vec<u8>, Error>

Reads the specified array of bytes from the storage.

If len + offset exceeds the length of the storage an appropriate Error should be returned or a panic may occur.

Source

fn set_len(&self, len: u64) -> Result<(), Error>

Sets the length of the storage.

When extending the storage the new positions should be zero initialized.

Source

fn sync_data(&self, eventual: bool) -> Result<(), Error>

Syncs all buffered data with the persistent storage.

If eventual is true, data may become persistent at some point after this call returns, but the storage must gaurantee that a write barrier is inserted: i.e. all writes before this call to sync_data() will become persistent before any writes that occur after.

Source

fn write(&self, offset: u64, data: &[u8]) -> Result<(), Error>

Writes the specified array to the storage.

Implementors§