Struct trie_db::triedb::TrieDB[][src]

pub struct TrieDB<'db, L> where
    L: TrieLayout
{ /* fields omitted */ }
Expand description

A Trie implementation using a generic HashDB backing database, a Hasher implementation to generate keys and a NodeCodec implementation to encode/decode the nodes.

Use it as a Trie trait object. You can use db() to get the backing database object. Use get and contains to query values associated with keys in the trie.

Example

use hash_db::Hasher;
use reference_trie::{RefTrieDBMut, RefTrieDB, Trie, TrieMut};
use trie_db::DBValue;
use keccak_hasher::KeccakHasher;
use memory_db::*;

let mut memdb = MemoryDB::<KeccakHasher, HashKey<_>, _>::default();
let mut root = Default::default();
RefTrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap();
let t = RefTrieDB::new(&memdb, &root).unwrap();
assert!(t.contains(b"foo").unwrap());
assert_eq!(t.get(b"foo").unwrap().unwrap(), b"bar".to_vec());

Implementations

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

Get the backing database.

Trait Implementations

Formats the value using the given formatter. Read more

Return the root of the trie.

Search for the key with the given query parameter. See the docs of the Query trait for more details. Read more

Returns a depth-first iterator over the elements of trie.

Is the trie empty?

Does the trie contain a given key?

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

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.