Struct trie_db::triedbmut::TrieDBMut[][src]

pub struct TrieDBMut<'a, L> where
    L: TrieLayout
{ /* fields omitted */ }
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

Create a new trie with backing database db and empty root.

Create a new trie with the backing database db and root. Returns an error if root` does not exist.

Get the backing database.

Get the backing database mutably.

Commit the in-memory changes to disk, freeing their storage and updating the state root.

Trait Implementations

Executes the destructor for this type. Read more

Return the root of the trie.

Is the trie empty?

What is the value of the given key in this trie?

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

Remove a key from the trie. Equivalent to making it equal to the empty value. Returns the old value associated with this key, if it existed. Read more

Does the trie contain a given key?

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.