[−][src]Struct reference_trie::TrieDB
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());
Methods
impl<'db, L> TrieDB<'db, L> where
L: TrieLayout,
[src]
L: TrieLayout,
pub fn new(
db: &'db (dyn HashDBRef<<L as TrieLayout>::Hash, Vec<u8>> + 'db),
root: &'db <<L as TrieLayout>::Hash as Hasher>::Out
) -> Result<TrieDB<'db, L>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>
[src]
db: &'db (dyn HashDBRef<<L as TrieLayout>::Hash, Vec<u8>> + 'db),
root: &'db <<L as TrieLayout>::Hash as Hasher>::Out
) -> Result<TrieDB<'db, L>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>
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 as TrieLayout>::Hash, Vec<u8>> + 'db)
[src]
&'db self
) -> &'db (dyn HashDBRef<<L as TrieLayout>::Hash, Vec<u8>> + 'db)
Get the backing database.
Trait Implementations
impl<'db, L> Debug for TrieDB<'db, L> where
L: TrieLayout,
[src]
L: TrieLayout,
impl<'db, L> Trie<L> for TrieDB<'db, L> where
L: TrieLayout,
[src]
L: TrieLayout,
fn root(&self) -> &<<L as TrieLayout>::Hash as Hasher>::Out
[src]
fn get_with<'a, 'key, Q>(
&'a self,
key: &'key [u8],
query: Q
) -> Result<Option<<Q as Query<<L as TrieLayout>::Hash>>::Item>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>> where
'a: 'key,
Q: Query<<L as TrieLayout>::Hash>,
[src]
&'a self,
key: &'key [u8],
query: Q
) -> Result<Option<<Q as Query<<L as TrieLayout>::Hash>>::Item>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>> where
'a: 'key,
Q: Query<<L as TrieLayout>::Hash>,
fn iter(
&'a self
) -> Result<Box<dyn TrieIterator<L, Item = Result<(Vec<u8>, Vec<u8>), Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>> + 'a>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>
[src]
&'a self
) -> Result<Box<dyn TrieIterator<L, Item = Result<(Vec<u8>, Vec<u8>), Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>> + 'a>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>
fn is_empty(&self) -> bool
[src]
fn contains(
&self,
key: &[u8]
) -> Result<bool, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>
[src]
&self,
key: &[u8]
) -> Result<bool, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>>
fn get<'a, 'key>(
&'a self,
key: &'key [u8]
) -> Result<Option<Vec<u8>>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>> where
'a: 'key,
[src]
&'a self,
key: &'key [u8]
) -> Result<Option<Vec<u8>>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>>> where
'a: 'key,
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> MaybeDebug for T where
T: Debug,
[src]
T: Debug,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,