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§
sourcetype ScanIterator<'a>: ScanIteratorT + 'a
where
Self: Sized + 'a
type ScanIterator<'a>: ScanIteratorT + 'a where Self: Sized + 'a
The iterator returned by scan().
Required Methods§
sourcefn delete(&mut self, key: &[u8]) -> CResult<i64>
fn delete(&mut self, key: &[u8]) -> CResult<i64>
Deletes a key, or does nothing if it does not exist.
sourcefn get(&mut self, key: &[u8]) -> CResult<Option<Vec<u8>>>
fn get(&mut self, key: &[u8]) -> CResult<Option<Vec<u8>>>
Gets a value for a key, if it exists.
sourcefn scan(&mut self, range: impl RangeBounds<Vec<u8>>) -> Self::ScanIterator<'_>where
Self: Sized,
fn scan(&mut self, range: impl RangeBounds<Vec<u8>>) -> Self::ScanIterator<'_>where
Self: Sized,
Iterates over an ordered range of key/value pairs.
sourcefn scan_dyn(
&mut self,
range: (Bound<Vec<u8>>, Bound<Vec<u8>>)
) -> Box<dyn ScanIteratorT + '_>
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.
Provided Methods§
sourcefn scan_prefix(&mut self, prefix: &[u8]) -> Self::ScanIterator<'_>where
Self: Sized,
fn scan_prefix(&mut self, prefix: &[u8]) -> Self::ScanIterator<'_>where
Self: Sized,
Iterates over all key/value pairs starting with prefix.