Struct trie_db::triedb::TrieDB

source ·
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,

source

pub fn db(&'db self) -> &'db dyn HashDBRef<L::Hash, DBValue>

Get the backing database.

Trait Implementations§

source§

impl<'db, 'cache, L> Debug for TrieDB<'db, 'cache, L>where L: TrieLayout,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'db, 'cache, L> Trie<L> for TrieDB<'db, 'cache, L>where L: TrieLayout,

source§

fn root(&self) -> &TrieHash<L>

Return the root of the trie.
source§

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>>

Search for the key with the given query parameter. See the docs of the Query trait for more details.
source§

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>>

Returns a depth-first iterator over the keys of elemets of trie.
source§

fn is_empty(&self) -> bool

Is the trie empty?
source§

fn contains(&self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>>

Does the trie contain a given key?
source§

fn get(&self, key: &[u8]) -> Result<Option<DBValue>, TrieHash<L>, CError<L>>

What is the value of the given key in this trie?

Auto Trait Implementations§

§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> MaybeDebug for Twhere T: Debug,