[][src]Struct trie_db::triedb::TrieDB

pub struct TrieDB<'db, L> where
    L: TrieLayout
{ /* fields omitted */ }

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, L> TrieDB<'db, L> where
    L: TrieLayout
[src]

pub fn new(
    db: &'db dyn HashDBRef<L::Hash, DBValue>,
    root: &'db TrieHash<L>
) -> Result<Self, TrieHash<L>, CError<L>>
[src]

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::Hash, DBValue>[src]

Get the backing database.

pub fn root_data(&self) -> Result<DBValue, TrieHash<L>, CError<L>>[src]

Get the data of the root node.

Trait Implementations

impl<'db, L> Trie<L> for TrieDB<'db, L> where
    L: TrieLayout
[src]

fn is_empty(&self) -> bool[src]

Is the trie empty?

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

Does the trie contain a given key?

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

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

impl<'db, L> Debug for TrieDB<'db, L> where
    L: TrieLayout
[src]

Auto Trait Implementations

impl<'db, L> Unpin for TrieDB<'db, L>

impl<'db, L> !Send for TrieDB<'db, L>

impl<'db, L> !Sync for TrieDB<'db, L>

impl<'db, L> !RefUnwindSafe for TrieDB<'db, L>

impl<'db, L> !UnwindSafe for TrieDB<'db, L>

Blanket Implementations

impl<T> MaybeDebug for T where
    T: Debug
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> MaybeDebug for T where
    T: Debug
[src]