StorageData

Trait StorageData 

Source
pub trait StorageData: Sized {
    // Required methods
    fn backup(&self, _name: &str) -> Result<(), DbError>;
    fn copy(&self, name: &str) -> Result<Self, DbError>;
    fn len(&self) -> u64;
    fn name(&self) -> &str;
    fn new(name: &str) -> Result<Self, DbError>;
    fn read(
        &self,
        pos: u64,
        value_len: u64,
    ) -> Result<StorageSlice<'_>, DbError>;
    fn rename(&mut self, new_name: &str) -> Result<(), DbError>;
    fn resize(&mut self, new_len: u64) -> Result<(), DbError>;
    fn write(&mut self, pos: u64, bytes: &[u8]) -> Result<(), DbError>;

    // Provided methods
    fn flush(&mut self) -> Result<(), DbError> { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

Minimum set of data operations required by the database to store & retrieve data.

Required Methods§

Source

fn backup(&self, _name: &str) -> Result<(), DbError>

Copy the underlying data storage to a new name. The default implementation does nothing. File implementations might need to copy the underlying file(s).

Source

fn copy(&self, name: &str) -> Result<Self, DbError>

Copies the storage to a new name.

Source

fn len(&self) -> u64

Returns the length of the underlying storage in bytes.

Source

fn name(&self) -> &str

Returns the name this storage was constructed with.

Source

fn new(name: &str) -> Result<Self, DbError>

Constructs or loads the storage name. The name might be a file name or other identifier.

Source

fn read(&self, pos: u64, value_len: u64) -> Result<StorageSlice<'_>, DbError>

Reads value_len bytes starting at pos. Returns StorageSlice (COW).

Source

fn rename(&mut self, new_name: &str) -> Result<(), DbError>

Changes the name of the storage changing also the names of the files (if the storage is file based).

Source

fn resize(&mut self, new_len: u64) -> Result<(), DbError>

Resizes the underlying storage to new_len. If the storage is enlarged as a result the new bytes should be initialized to 0_u8.

Source

fn write(&mut self, pos: u64, bytes: &[u8]) -> Result<(), DbError>

Writes the bytes to the underlying storage at pos. The implementation must handle the case where the pos + bytes.len() exceeds the current len().

Provided Methods§

Source

fn flush(&mut self) -> Result<(), DbError>

Flushes any buffers to the underlying storage (e.g. file). The default implementation does nothing.

Source

fn is_empty(&self) -> bool

Convenience method that returns len() == 0.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§