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§
Trait Implementations§
Source§impl<H> Database<H> for MemDb<H>
impl<H> Database<H> for MemDb<H>
Source§fn commit(&self, transaction: Transaction<H>) -> Result<()>
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>>
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>>
fn lookup(&self, hash: &H) -> Option<Vec<u8>>
Retrieve the first preimage previously
store
d 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<()>
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 set(&self, col: ColumnId, key: &[u8], value: &[u8]) -> Result<()>
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 with_lookup(&self, hash: &H, f: &mut dyn FnMut(&[u8]))
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 moreSource§fn store(&self, hash: &H, preimage: &[u8]) -> Result<()>
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
.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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more