pub trait Collection:
Sync
+ Send
+ 'static {
// Required methods
fn name(&self) -> &str;
fn get(&self, key: &str) -> Result<Vec<u8>, Error>;
fn put(&mut self, key: &str, data: &[u8]) -> Result<(), Error>;
fn del(&mut self, key: &str) -> Result<(), Error>;
fn last(&self) -> Result<Option<(String, Vec<u8>)>, Error>;
fn purge(&mut self) -> Result<(), Error>;
fn iter<'a>(&'a self, reverse: bool) -> Result<CollectionIter<'a>, Error>;
// Provided method
fn get_by_range(
&self,
from: Option<String>,
quantity: isize,
) -> Result<Vec<Vec<u8>>, Error> { ... }
}Expand description
Ordered key-value storage used to persist event sequences.
Keys are typically zero-padded sequence numbers (e.g. "00000000000000000042"),
which makes the last-entry and range queries efficient. Implementations must
be Send + Sync + 'static.
Required Methods§
Sourcefn get(&self, key: &str) -> Result<Vec<u8>, Error>
fn get(&self, key: &str) -> Result<Vec<u8>, Error>
Returns the value stored under key.
Returns Error::EntryNotFound if the key does not exist.
Sourcefn put(&mut self, key: &str, data: &[u8]) -> Result<(), Error>
fn put(&mut self, key: &str, data: &[u8]) -> Result<(), Error>
Associates data with key, inserting or replacing any previous value.
Sourcefn del(&mut self, key: &str) -> Result<(), Error>
fn del(&mut self, key: &str) -> Result<(), Error>
Removes the entry for key.
Returns Error::EntryNotFound if the key does not exist.
Sourcefn last(&self) -> Result<Option<(String, Vec<u8>)>, Error>
fn last(&self) -> Result<Option<(String, Vec<u8>)>, Error>
Returns the last key-value pair in insertion/sort order, or None if the collection is empty.
Sourcefn iter<'a>(&'a self, reverse: bool) -> Result<CollectionIter<'a>, Error>
fn iter<'a>(&'a self, reverse: bool) -> Result<CollectionIter<'a>, Error>
Returns an iterator over all key-value pairs.
Pass reverse = true to iterate in descending key order.
Returns an error if the backend cannot acquire the necessary locks to start
iteration; individual items in the iterator may also yield errors.
Provided Methods§
Sourcefn get_by_range(
&self,
from: Option<String>,
quantity: isize,
) -> Result<Vec<Vec<u8>>, Error>
fn get_by_range( &self, from: Option<String>, quantity: isize, ) -> Result<Vec<Vec<u8>>, Error>
Returns at most quantity.abs() values, optionally starting after from.
If from is Some(key), iteration begins at the entry immediately after key.
A positive quantity iterates forward; negative iterates in reverse.
Returns Error::EntryNotFound if from is provided but does not exist.