Trait Store

Source
pub trait Store {
    // Required methods
    fn push(
        &self,
        db: &'static str,
        key: &str,
        value: Vec<u8>,
    ) -> Result<(), Error>;
    fn pull<F, T>(
        &self,
        db: &'static str,
        key: &str,
        formatter: F,
    ) -> Result<T, Error>
       where F: Fn(&[u8]) -> Result<T, Error>;
    fn iter<F>(&self, db: &'static str, prefix: &str, f: F) -> Result<(), Error>
       where F: Fn(&[u8]) -> Continue;
    fn rm(&self, db: &'static str, key: &str) -> Result<(), Error>;

    // Provided method
    fn all<F, T>(
        &self,
        db: &'static str,
        prefix: &str,
        formatter: F,
    ) -> Result<Vec<T>, Error>
       where F: Fn(&[u8]) -> Result<T, Error> { ... }
}
Expand description

Trait that defines a Store that can be implemented to save Model objects in memory, filesystem or the network

Required Methods§

Source

fn push(&self, db: &'static str, key: &str, value: Vec<u8>) -> Result<(), Error>

Stores the value in the database with the corresponding key

Source

fn pull<F, T>( &self, db: &'static str, key: &str, formatter: F, ) -> Result<T, Error>
where F: Fn(&[u8]) -> Result<T, Error>,

Retrieves the value in the database with the corresponding key Returns an error if the key doesn’t exists

Source

fn iter<F>(&self, db: &'static str, prefix: &str, f: F) -> Result<(), Error>
where F: Fn(&[u8]) -> Continue,

Iterates over all objects that starts with the prefix and run the function f. If f returns Continue(false) the iteration stops

Source

fn rm(&self, db: &'static str, key: &str) -> Result<(), Error>

Remove the corresponding data in the database by key

Provided Methods§

Source

fn all<F, T>( &self, db: &'static str, prefix: &str, formatter: F, ) -> Result<Vec<T>, Error>
where F: Fn(&[u8]) -> Result<T, Error>,

Retrieves all items in the database that starts with the prefix key

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Store for mdl::bcache::Cache

Source§

impl Store for mdl::cache::Cache