Skip to main content

ClientDatabaseStorageBackend

Trait ClientDatabaseStorageBackend 

Source
pub trait ClientDatabaseStorageBackend:
    Debug
    + Send
    + Sync
    + 'static {
    // Required methods
    fn num_pages(&self) -> u32;
    fn read(
        &self,
        buffer: OwnedPages,
        num_pages: u32,
        offset: u32,
    ) -> Receiver<(Result<(), StorageBackendError>, OwnedPages)> ⓘ;
    fn write(
        &self,
        buffer: SharedPages,
        offset: u32,
    ) -> Receiver<(Result<(), StorageBackendError>, SharedPages)> ⓘ;
}
Expand description

Storage backend to be used by ClientDatabase.

Read and write errors are fatal: the database doesn’t try to recover from them, and the node is expected to stop when it encounters one.

Required Methods§

Source

fn num_pages(&self) -> u32

Total number of pages available for reads/writes

Source

fn read( &self, buffer: OwnedPages, num_pages: u32, offset: u32, ) -> Receiver<(Result<(), StorageBackendError>, OwnedPages)> ⓘ

Read num_pages pages at offset (in pages) into buffer, replacing its contents.

The buffer grows if its capacity is smaller than num_pages pages. Existing contents are discarded, so they are never copied, and StorageBackendError::AllocationFailed is returned if growing fails. On success the buffer contains exactly num_pages pages. The buffer is returned back regardless of the result.

The read is started before this method returns.

Source

fn write( &self, buffer: SharedPages, offset: u32, ) -> Receiver<(Result<(), StorageBackendError>, SharedPages)> ⓘ

Write the contents of buffer, which are whole pages, at offset (in pages).

The buffer is shared, so the caller can keep reading it while the write is in progress. The buffer is returned back regardless of the result.

The write is started before this method returns.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§