pub struct TrieDB<'db, 'cache, 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);
assert!(t.contains(b"foo").unwrap());
assert_eq!(t.get(b"foo").unwrap().unwrap(), b"bar".to_vec());
Implementations§
source§impl<'db, 'cache, L> TrieDB<'db, 'cache, L>where
L: TrieLayout,
impl<'db, 'cache, L> TrieDB<'db, 'cache, L>where
L: TrieLayout,
sourcepub fn into_double_ended_iter(
&'db self
) -> Result<TrieDBDoubleEndedIterator<'db, 'cache, L>, TrieHash<L>, CError<L>>
pub fn into_double_ended_iter( &'db self ) -> Result<TrieDBDoubleEndedIterator<'db, 'cache, L>, TrieHash<L>, CError<L>>
Create TrieDBDoubleEndedIterator
from TrieDB
.
sourcepub fn into_node_double_ended_iter(
&'db self
) -> Result<TrieDBNodeDoubleEndedIterator<'db, 'cache, L>, TrieHash<L>, CError<L>>
pub fn into_node_double_ended_iter( &'db self ) -> Result<TrieDBNodeDoubleEndedIterator<'db, 'cache, L>, TrieHash<L>, CError<L>>
Create TrieDBNodeDoubleEndedIterator
from TrieDB
.
sourcepub fn into_key_double_ended_iter(
&'db self
) -> Result<TrieDBKeyDoubleEndedIterator<'db, 'cache, L>, TrieHash<L>, CError<L>>
pub fn into_key_double_ended_iter( &'db self ) -> Result<TrieDBKeyDoubleEndedIterator<'db, 'cache, L>, TrieHash<L>, CError<L>>
create TrieDBKeyDoubleEndedIterator
from TrieDB
.
sourcepub fn into_fat_double_ended_iter(
&'db self
) -> Result<FatDBDoubleEndedIterator<'db, 'cache, L>, TrieHash<L>, CError<L>>
pub fn into_fat_double_ended_iter( &'db self ) -> Result<FatDBDoubleEndedIterator<'db, 'cache, L>, TrieHash<L>, CError<L>>
create FatDBDoubleEndedIterator
from TrieDB
.
Trait Implementations§
source§impl<'db, 'cache, L> Debug for TrieDB<'db, 'cache, L>where
L: TrieLayout,
impl<'db, 'cache, L> Debug for TrieDB<'db, 'cache, L>where
L: TrieLayout,
source§impl<'db, 'cache, L> Trie<L> for TrieDB<'db, 'cache, L>where
L: TrieLayout,
impl<'db, 'cache, L> Trie<L> for TrieDB<'db, 'cache, L>where
L: TrieLayout,
source§fn get_hash(
&self,
key: &[u8]
) -> Result<Option<TrieHash<L>>, TrieHash<L>, CError<L>>
fn get_hash( &self, key: &[u8] ) -> Result<Option<TrieHash<L>>, TrieHash<L>, CError<L>>
Returns the hash of the value for
key
.source§fn get_with<Q: Query<L::Hash>>(
&self,
key: &[u8],
query: Q
) -> Result<Option<Q::Item>, TrieHash<L>, CError<L>>
fn get_with<Q: Query<L::Hash>>( &self, key: &[u8], query: Q ) -> Result<Option<Q::Item>, TrieHash<L>, CError<L>>
Search for the key with the given query parameter. See the docs of the
Query
trait for more details.source§fn lookup_first_descendant(
&self,
key: &[u8]
) -> Result<Option<MerkleValue<TrieHash<L>>>, TrieHash<L>, CError<L>>
fn lookup_first_descendant( &self, key: &[u8] ) -> Result<Option<MerkleValue<TrieHash<L>>>, TrieHash<L>, CError<L>>
Look up the
MerkleValue
of the node that is the closest descendant for the provided
key. Read moresource§fn 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.
source§fn key_iter<'a>(
&'a self
) -> Result<Box<dyn TrieIterator<L, Item = TrieKeyItem<TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>
fn key_iter<'a>( &'a self ) -> Result<Box<dyn TrieIterator<L, Item = TrieKeyItem<TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>
Returns a depth-first iterator over the keys of elemets of trie.
Auto Trait Implementations§
impl<'db, 'cache, L> !Freeze for TrieDB<'db, 'cache, L>
impl<'db, 'cache, L> !RefUnwindSafe for TrieDB<'db, 'cache, L>
impl<'db, 'cache, L> !Send for TrieDB<'db, 'cache, L>
impl<'db, 'cache, L> !Sync for TrieDB<'db, 'cache, L>
impl<'db, 'cache, L> Unpin for TrieDB<'db, 'cache, L>
impl<'db, 'cache, L> !UnwindSafe for TrieDB<'db, 'cache, L>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more