Struct trie_db::triedbmut::TrieDBMut [−][src]
pub struct TrieDBMut<'a, L> where
L: TrieLayout, { /* fields omitted */ }A Trie implementation using a generic HashDB backing database.
Use it as a TrieMut trait object. You can use db() to get the backing database object.
Note that changes are not committed to the database until commit is called.
Querying the root or dropping the trie will commit automatically.
Example
ⓘ
use hash_db::Hasher; use reference_trie::{RefTrieDBMut, TrieMut}; use trie_db::DBValue; use keccak_hasher::KeccakHasher; use memory_db::*; let mut memdb = MemoryDB::<KeccakHasher, HashKey<_>, DBValue>::default(); let mut root = Default::default(); let mut t = RefTrieDBMut::new(&mut memdb, &mut root); assert!(t.is_empty()); assert_eq!(*t.root(), KeccakHasher::hash(&[0u8][..])); t.insert(b"foo", b"bar").unwrap(); assert!(t.contains(b"foo").unwrap()); assert_eq!(t.get(b"foo").unwrap().unwrap(), b"bar".to_vec()); t.remove(b"foo").unwrap(); assert!(!t.contains(b"foo").unwrap());
Implementations
impl<'a, L> TrieDBMut<'a, L> where
L: TrieLayout, [src]
impl<'a, L> TrieDBMut<'a, L> where
L: TrieLayout, [src]pub fn new(
db: &'a mut dyn HashDB<L::Hash, DBValue>,
root: &'a mut TrieHash<L>
) -> Self[src]
db: &'a mut dyn HashDB<L::Hash, DBValue>,
root: &'a mut TrieHash<L>
) -> Self
Create a new trie with backing database db and empty root.
pub fn from_existing(
db: &'a mut dyn HashDB<L::Hash, DBValue>,
root: &'a mut TrieHash<L>
) -> Result<Self, TrieHash<L>, CError<L>>[src]
db: &'a mut dyn HashDB<L::Hash, DBValue>,
root: &'a mut TrieHash<L>
) -> Result<Self, TrieHash<L>, CError<L>>
Create a new trie with the backing database db and root. Returns an error if root` does not exist.
pub fn db(&self) -> &dyn HashDB<L::Hash, DBValue>[src]
Get the backing database.
pub fn db_mut(&mut self) -> &mut dyn HashDB<L::Hash, DBValue>[src]
Get the backing database mutably.
pub fn commit(&mut self)[src]
Commit the in-memory changes to disk, freeing their storage and updating the state root.
Trait Implementations
impl<'a, L> TrieMut<L> for TrieDBMut<'a, L> where
L: TrieLayout, [src]
impl<'a, L> TrieMut<L> for TrieDBMut<'a, L> where
L: TrieLayout, [src]fn root(&mut self) -> &TrieHash<L>[src]
fn is_empty(&self) -> bool[src]
fn get<'x, 'key>(
&'x self,
key: &'key [u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>> where
'x: 'key, [src]
&'x self,
key: &'key [u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>> where
'x: 'key,
fn insert(
&mut self,
key: &[u8],
value: &[u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>>[src]
&mut self,
key: &[u8],
value: &[u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>>
fn remove(
&mut self,
key: &[u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>>[src]
&mut self,
key: &[u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>>
fn contains(&self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>>[src]
Auto Trait Implementations
impl<'a, L> !RefUnwindSafe for TrieDBMut<'a, L>
impl<'a, L> Send for TrieDBMut<'a, L>
impl<'a, L> Sync for TrieDBMut<'a, L>
impl<'a, L> Unpin for TrieDBMut<'a, L> where
<<L as TrieLayout>::Hash as Hasher>::Out: Unpin,
<<L as TrieLayout>::Hash as Hasher>::Out: Unpin,