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
extern crate trie_db;
extern crate reference_trie;
extern crate hash_db;
extern crate keccak_hasher;
extern crate memory_db;
use hash_db::Hasher;
use reference_trie::{RefTrieDBMut, RefTrieDB, Trie, TrieMut};
use trie_db::DBValue;
use keccak_hasher::KeccakHasher;
use memory_db::*;
fn main() {
let mut memdb = MemoryDB::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(), DBValue::from_slice(b"bar"));
}
Implementations
sourceimpl<'db, H, C> TrieDB<'db, H, C> where
H: Hasher,
C: NodeCodec<H>,
impl<'db, H, C> TrieDB<'db, H, C> where
H: Hasher,
C: NodeCodec<H>,
Trait Implementations
sourceimpl<'db, H, C> Trie<H, C> for TrieDB<'db, H, C> where
H: Hasher,
C: NodeCodec<H>,
impl<'db, H, C> Trie<H, C> for TrieDB<'db, H, C> where
H: Hasher,
C: NodeCodec<H>,
sourcefn get_with<'a, 'key, Q: Query<H>>(
&'a self,
key: &'key [u8],
query: Q
) -> Result<Option<Q::Item>, H::Out, C::Error> where
'a: 'key,
fn get_with<'a, 'key, Q: Query<H>>(
&'a self,
key: &'key [u8],
query: Q
) -> Result<Option<Q::Item>, H::Out, C::Error> 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<H, C, Item = TrieItem<'_, H::Out, C::Error>> + 'a>, H::Out, C::Error>
fn iter<'a>(
&'a self
) -> Result<Box<dyn TrieIterator<H, C, Item = TrieItem<'_, H::Out, C::Error>> + 'a>, H::Out, C::Error>
Returns a depth-first iterator over the elements of trie.
Auto Trait Implementations
impl<'db, H, C> !RefUnwindSafe for TrieDB<'db, H, C>
impl<'db, H, C> !Send for TrieDB<'db, H, C>
impl<'db, H, C> !Sync for TrieDB<'db, H, C>
impl<'db, H, C> Unpin for TrieDB<'db, H, C> where
C: Unpin,
impl<'db, H, C> !UnwindSafe for TrieDB<'db, H, C>
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