pub struct TrieDB<'db, L> where
L: TrieLayout, { /* private fields */ }
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
sourceimpl<'db, L> TrieDB<'db, L> where
L: TrieLayout,
impl<'db, L> TrieDB<'db, L> where
L: TrieLayout,
Trait Implementations
sourceimpl<'db, L> Debug for TrieDB<'db, L> where
L: TrieLayout,
impl<'db, L> Debug for TrieDB<'db, L> where
L: TrieLayout,
sourceimpl<'db, L> Trie<L> for TrieDB<'db, L> where
L: TrieLayout,
impl<'db, L> Trie<L> for TrieDB<'db, L> where
L: TrieLayout,
sourcefn 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,
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,
Search for the key with the given query parameter. See the docs of the Query
trait for more details. Read more
sourcefn iter<'a>(
&'a self
) -> Result<Box<dyn TrieIterator<L, Item = TrieItem<'_, TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>
fn iter<'a>(
&'a self
) -> Result<Box<dyn TrieIterator<L, Item = TrieItem<'_, TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>
Returns a depth-first iterator over the elements of trie.
Auto Trait Implementations
impl<'db, L> !RefUnwindSafe for TrieDB<'db, L>
impl<'db, L> !Send for TrieDB<'db, L>
impl<'db, L> !Sync for TrieDB<'db, L>
impl<'db, L> Unpin for TrieDB<'db, L>
impl<'db, L> !UnwindSafe for TrieDB<'db, L>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more