Struct trie_db::triedb::TrieDB [−][src]
pub struct TrieDB<'db, L> where
L: TrieLayout, { /* fields omitted */ }
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
impl<'db, L> TrieDB<'db, L> where
L: TrieLayout,
[src]
impl<'db, L> TrieDB<'db, L> where
L: TrieLayout,
[src]pub fn new(
db: &'db dyn HashDBRef<L::Hash, DBValue>,
root: &'db TrieHash<L>
) -> Result<Self, TrieHash<L>, CError<L>>
[src]
db: &'db dyn HashDBRef<L::Hash, DBValue>,
root: &'db 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(&'db self) -> &'db dyn HashDBRef<L::Hash, DBValue>
[src]
Get the backing database.
Trait Implementations
impl<'db, L> Debug for TrieDB<'db, L> where
L: TrieLayout,
[src]
impl<'db, L> Debug for TrieDB<'db, L> where
L: TrieLayout,
[src]impl<'db, L> Trie<L> for TrieDB<'db, L> where
L: TrieLayout,
[src]
impl<'db, L> Trie<L> for TrieDB<'db, L> where
L: TrieLayout,
[src]fn root(&self) -> &TrieHash<L>
[src]
fn get_with<'a, 'key, Q: Query<L::Hash>>(
&'a self,
key: &'key [u8],
query: Q
) -> Result<Option<Q::Item>, TrieHash<L>, CError<L>> where
'a: 'key,
[src]
&'a self,
key: &'key [u8],
query: Q
) -> Result<Option<Q::Item>, TrieHash<L>, CError<L>> where
'a: 'key,
fn iter<'a>(
&'a self
) -> Result<Box<dyn TrieIterator<L, Item = TrieItem<'_, TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>
[src]
&'a self
) -> Result<Box<dyn TrieIterator<L, Item = TrieItem<'_, TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>
fn is_empty(&self) -> bool
[src]
fn contains(&self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>>
[src]
fn get<'a, 'key>(
&'a self,
key: &'key [u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>> where
'a: 'key,
[src]
&'a self,
key: &'key [u8]
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>> where
'a: 'key,