Skip to main content

StorageBackend

Trait StorageBackend 

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

    // Provided method
    fn close(&self) -> 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, out: &mut [u8]) -> Result<(), Error>

Reads the specified array of bytes from the storage.

If out.len() + offset exceeds the length of the storage an appropriate Error must be returned.

Source

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

Sets the length of the storage.

New positions in the storage must be initialized to zero.

Source

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

Syncs all buffered data with the persistent storage.

Source

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

Writes the specified array to the storage.

Provided Methods§

Source

fn close(&self) -> Result<(), Error>

Release any resources held by the backend

Note: redb will not access the backend after calling this method and will call it exactly once when the Database is dropped

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§