Trait kv_rs::storage::engine::Engine

source ·
pub trait Engine: Display + Send + Sync {
    type ScanIterator<'a>: ScanIteratorT + 'a
       where Self: Sized + 'a;

    // Required methods
    fn delete(&mut self, key: &[u8]) -> CResult<i64>;
    fn flush(&mut self) -> CResult<()>;
    fn get(&mut self, key: &[u8]) -> CResult<Option<Vec<u8>>>;
    fn scan(
        &mut self,
        range: impl RangeBounds<Vec<u8>>
    ) -> Self::ScanIterator<'_>
       where Self: Sized;
    fn scan_dyn(
        &mut self,
        range: (Bound<Vec<u8>>, Bound<Vec<u8>>)
    ) -> Box<dyn ScanIteratorT + '_>;
    fn set(&mut self, key: &[u8], value: Vec<u8>) -> CResult<()>;
    fn status(&mut self) -> CResult<Status>;

    // Provided method
    fn scan_prefix(&mut self, prefix: &[u8]) -> Self::ScanIterator<'_>
       where Self: Sized { ... }
}
Expand description

A key/value storage engine, where both keys and values are arbitrary byte strings between 0 B and 2 GB, stored in lexicographical key order. Writes are only guaranteed durable after calling flush().

Only supports single-threaded use since all methods (including reads) take a mutable reference – serialized access can’t be avoided anyway, since both Raft execution and file access is serial.

Required Associated Types§

source

type ScanIterator<'a>: ScanIteratorT + 'a where Self: Sized + 'a

The iterator returned by scan().

Required Methods§

source

fn delete(&mut self, key: &[u8]) -> CResult<i64>

Deletes a key, or does nothing if it does not exist.

source

fn flush(&mut self) -> CResult<()>

Flushes any buffered data to the underlying storage medium.

source

fn get(&mut self, key: &[u8]) -> CResult<Option<Vec<u8>>>

Gets a value for a key, if it exists.

source

fn scan(&mut self, range: impl RangeBounds<Vec<u8>>) -> Self::ScanIterator<'_>
where Self: Sized,

Iterates over an ordered range of key/value pairs.

source

fn scan_dyn( &mut self, range: (Bound<Vec<u8>>, Bound<Vec<u8>>) ) -> Box<dyn ScanIteratorT + '_>

Like scan, but can be used from trait objects. The iterator will use dynamic dispatch, which has a minor performance penalty.

source

fn set(&mut self, key: &[u8], value: Vec<u8>) -> CResult<()>

Sets a value for a key, replacing the existing value if any.

source

fn status(&mut self) -> CResult<Status>

Returns engine status.

Provided Methods§

source

fn scan_prefix(&mut self, prefix: &[u8]) -> Self::ScanIterator<'_>
where Self: Sized,

Iterates over all key/value pairs starting with prefix.

Implementors§