Skip to main content

StorageReadView

Trait StorageReadView 

Source
pub trait StorageReadView: Send + Sync {
    // Required methods
    fn get(
        &self,
        table: &'static str,
        key: &[u8],
    ) -> Result<Option<Vec<u8>>, StoreError>;
    fn prefix_iterator(
        &self,
        table: &'static str,
        prefix: &[u8],
    ) -> Result<Box<dyn Iterator<Item = PrefixResult> + '_>, StoreError>;
    fn first_key(
        &self,
        table: &'static str,
    ) -> Result<Option<Vec<u8>>, StoreError>;
    fn last_key(
        &self,
        table: &'static str,
    ) -> Result<Option<Vec<u8>>, StoreError>;

    // Provided method
    fn multi_get(
        &self,
        table: &'static str,
        keys: &[&[u8]],
    ) -> Vec<Result<Option<Vec<u8>>, StoreError>> { ... }
}
Expand description

Read-only transaction interface. Provides methods to read data from the database

Required Methods§

Source

fn get( &self, table: &'static str, key: &[u8], ) -> Result<Option<Vec<u8>>, StoreError>

Retrieves a value by key from the specified table.

Source

fn prefix_iterator( &self, table: &'static str, prefix: &[u8], ) -> Result<Box<dyn Iterator<Item = PrefixResult> + '_>, StoreError>

Returns the key-value pairs of table from the first key not less than prefix onward, in key order. The iterator does not stop where keys stop starting with prefix: the RocksDB backend configures no prefix extractor, so this is a plain seek. Callers stop once keys leave the range they want, and may seek into the middle of a prefix.

Source

fn first_key(&self, table: &'static str) -> Result<Option<Vec<u8>>, StoreError>

Returns the lowest key in table by lexicographic order, or None if the table is empty. Backends that support forward iteration (e.g. RocksDB IteratorMode::Start) should implement this in O(1).

Source

fn last_key(&self, table: &'static str) -> Result<Option<Vec<u8>>, StoreError>

Returns the highest key in table by lexicographic order, or None if the table is empty. Backends that support reverse iteration (e.g. RocksDB IteratorMode::End) should implement this in O(1).

Provided Methods§

Source

fn multi_get( &self, table: &'static str, keys: &[&[u8]], ) -> Vec<Result<Option<Vec<u8>>, StoreError>>

Retrieves multiple values by key from the specified table. Returns results in the same order as the input keys. Backends that support batched reads (e.g. RocksDB multi_get_cf) should override this for better throughput. Callers should not assume multi_get is asymptotically faster than get; on backends without a batched read primitive (e.g. the in-memory backend) the default impl below is equivalent to N independent get calls.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§