Struct sp_database::MemDb
source · [−]Expand description
This implements Database
as an in-memory hash map. commit
is not atomic.
Implementations
Trait Implementations
sourceimpl<H> Database<H> for MemDb<H> where
H: Clone + Send + Sync + Eq + PartialEq + Default + Hash,
impl<H> Database<H> for MemDb<H> where
H: Clone + Send + Sync + Eq + PartialEq + Default + Hash,
sourcefn 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. Read more
sourcefn 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. Read more
sourcefn 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. Read more
sourcefn 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. Read more
sourcefn contains(&self, col: ColumnId, key: &[u8]) -> bool
fn contains(&self, col: ColumnId, key: &[u8]) -> bool
Check if the value exists in the database without retrieving it.
sourcefn with_get(&self, col: ColumnId, key: &[u8], f: &mut dyn FnMut(&[u8]))
fn with_get(&self, col: ColumnId, key: &[u8], f: &mut dyn FnMut(&[u8]))
Call f
with the value previously stored against key
. Read more
sourcefn 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.
sourcefn 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 more
sourcefn 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
. Read more
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more