pub struct TrieDBMut<'a, L>where
L: TrieLayout,{ /* private fields */ }
Expand description
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§
Trait Implementations§
source§impl<'a, L> Drop for TrieDBMut<'a, L>where
L: TrieLayout,
impl<'a, L> Drop for TrieDBMut<'a, L>where
L: TrieLayout,
source§impl<'a, L> TrieMut<L> for TrieDBMut<'a, L>where
L: TrieLayout,
impl<'a, L> TrieMut<L> for TrieDBMut<'a, L>where
L: TrieLayout,
source§fn get<'x, 'key>(
&'x self,
key: &'key [u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>>where
'x: 'key,
fn get<'x, 'key>(
&'x self,
key: &'key [u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>>where
'x: 'key,
What is the value of the given key in this trie?
source§fn insert(
&mut self,
key: &[u8],
value: &[u8]
) -> Result<Option<Value<L>>, TrieHash<L>, CError<L>>
fn insert(
&mut self,
key: &[u8],
value: &[u8]
) -> Result<Option<Value<L>>, TrieHash<L>, CError<L>>
Insert a
key
/value
pair into the trie. An empty value is equivalent to removing
key
from the trie. Returns the old value associated with this key, if it existed. Read more