[−][src]Struct trie_db::triedb::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
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::<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(), DBValue::from_slice(b"bar")); }
Methods
impl<'db, H, C> TrieDB<'db, H, C> where
H: Hasher,
C: NodeCodec<H>,
[src]
H: Hasher,
C: NodeCodec<H>,
pub fn new(
db: &'db dyn HashDBRef<H, DBValue>,
root: &'db H::Out
) -> Result<Self, H::Out, C::Error>
[src]
db: &'db dyn HashDBRef<H, DBValue>,
root: &'db H::Out
) -> Result<Self, H::Out, C::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<H, DBValue>
[src]
Get the backing database.
pub fn root_data(&self) -> Result<DBValue, H::Out, C::Error>
[src]
Get the data of the root node.
Trait Implementations
impl<'db, H, C> Trie<H, C> for TrieDB<'db, H, C> where
H: Hasher,
C: NodeCodec<H>,
[src]
H: Hasher,
C: NodeCodec<H>,
fn root(&self) -> &H::Out
[src]
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,
[src]
&'a self,
key: &'key [u8],
query: Q
) -> Result<Option<Q::Item>, H::Out, C::Error> where
'a: 'key,
fn iter<'a>(
&'a self
) -> Result<Box<dyn TrieIterator<H, C, Item = TrieItem<H::Out, C::Error>> + 'a>, H::Out, C::Error>
[src]
&'a self
) -> Result<Box<dyn TrieIterator<H, C, Item = TrieItem<H::Out, C::Error>> + 'a>, H::Out, C::Error>
fn is_empty(&self) -> bool
[src]
Is the trie empty?
fn contains(&self, key: &[u8]) -> Result<bool, H::Out, C::Error>
[src]
Does the trie contain a given key?
fn get<'a, 'key>(
&'a self,
key: &'key [u8]
) -> Result<Option<DBValue>, H::Out, C::Error> where
'a: 'key,
[src]
&'a self,
key: &'key [u8]
) -> Result<Option<DBValue>, H::Out, C::Error> where
'a: 'key,
What is the value of the given key in this trie?
impl<'db, H, C> Debug for TrieDB<'db, H, C> where
H: Hasher,
C: NodeCodec<H>,
[src]
H: Hasher,
C: NodeCodec<H>,
Auto Trait Implementations
Blanket Implementations
impl<T> MaybeDebug for T where
T: Debug,
[src]
T: Debug,
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom 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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> MaybeDebug for T where
T: Debug,
[src]
T: Debug,