Struct Cache

Source
pub struct Cache {
    pub env: Environment,
    pub path: String,
    /* private fields */
}
Expand description

LMDB cache. This struct implements the Store trait so it can be used to cache Model structs

Fields§

§env: Environment

LMDB environment

§path: String

database path in the filesystem

Implementations§

Source§

impl Cache

Source

pub fn new(path: &str) -> Result<Cache, Error>

Source

pub fn db(&self, name: &'static str) -> Result<Database, Error>

Source

pub fn rw<F, T>(&self, db: &'static str, op: F) -> Result<T, Error>
where F: Fn(RwCursor<'_>) -> Result<T, Error>,

Source

pub fn ro<F, T>(&self, db: &'static str, op: F) -> Result<T, Error>
where F: Fn(RoCursor<'_>) -> Result<T, Error>,

Trait Implementations§

Source§

impl Store for Cache

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
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

Auto Trait Implementations§

§

impl !Freeze for Cache

§

impl !RefUnwindSafe for Cache

§

impl Send for Cache

§

impl !Sync for Cache

§

impl Unpin for Cache

§

impl UnwindSafe for Cache

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.