MemDb

Struct MemDb 

Source
pub struct MemDb<H: Clone + Send + Sync + Eq + PartialEq + Default + Hash>(/* private fields */);
Expand description

This implements Database as an in-memory hash map. commit is not atomic.

Implementations§

Source§

impl<H> MemDb<H>
where H: Clone + Send + Sync + Eq + PartialEq + Default + Hash,

Source

pub fn new() -> Self

Create a new instance

Source

pub fn count(&self, col: ColumnId) -> usize

Count number of values in a column

Trait Implementations§

Source§

impl<H> Database<H> for MemDb<H>
where H: Clone + Send + Sync + Eq + PartialEq + Default + Hash,

Source§

fn commit(&self, transaction: Transaction<H>) -> Result<()>

Commit the transaction to the database atomically. Any further calls to get or lookup will reflect the new state.
Source§

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

Retrieve the value previously stored against key or None if key is not currently in the database.
Source§

fn lookup(&self, hash: &H) -> Option<Vec<u8>>

Retrieve the first preimage previously stored for hash or None if no preimage is currently stored.
Source§

fn commit_ref<'a>( &self, transaction: &mut dyn Iterator<Item = ChangeRef<'a, H>>, ) -> Result<()>

Commit the transaction to the database atomically. Any further calls to get or lookup will reflect the new state.
Source§

fn with_get(&self, col: ColumnId, key: &[u8], f: &mut dyn FnMut(&[u8]))

Call f with the value previously stored against key. Read more
Source§

fn set(&self, col: ColumnId, key: &[u8], value: &[u8]) -> Result<()>

Set the value of key in col to value, replacing anything that is there currently.
Source§

fn remove(&self, col: ColumnId, key: &[u8]) -> Result<()>

Remove the value of key in col.
Source§

fn with_lookup(&self, hash: &H, f: &mut dyn FnMut(&[u8]))

Call f with the preimage stored for hash and return the result, or None if no preimage is currently stored. Read more
Source§

fn store(&self, hash: &H, preimage: &[u8]) -> Result<()>

Store the preimage of hash into the database, so that it may be looked up later with Database::lookup. This may be called multiple times, but Database::lookup but subsequent calls will ignore preimage and simply increase the number of references on hash.
Source§

fn release(&self, hash: &H) -> Result<()>

Release the preimage of hash from the database. An equal number of these to the number of corresponding stores must have been given before it is legal for Database::lookup to be unable to provide the preimage.
Source§

impl<H: Default + Clone + Send + Sync + Eq + PartialEq + Default + Hash> Default for MemDb<H>

Source§

fn default() -> MemDb<H>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<H> !Freeze for MemDb<H>

§

impl<H> !RefUnwindSafe for MemDb<H>

§

impl<H> Send for MemDb<H>

§

impl<H> Sync for MemDb<H>

§

impl<H> Unpin for MemDb<H>
where H: Unpin,

§

impl<H> UnwindSafe for MemDb<H>
where H: UnwindSafe,

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.