Struct patricia_trie::triedb::TrieDB[][src]

pub struct TrieDB<'db, H, C> where
    H: Hasher + 'db,
    C: NodeCodec<H>, 
{ /* 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 patricia_trie as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate hashdb;
extern crate keccak_hasher;
extern crate memorydb;
extern crate ethereum_types;

use trie::*;
use hashdb::*;
use keccak_hasher::KeccakHasher;
use memorydb::*;
use ethereum_types::H256;
use ethtrie::{TrieDB, TrieDBMut};


fn main() {
  let mut memdb = MemoryDB::<KeccakHasher, DBValue>::new();
  let mut root = H256::new();
  TrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap();
  let t = TrieDB::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]

Create a new trie with the backing database db and root Returns an error if root does not exist

Get the backing database.

Trait Implementations

impl<'db, H, C> Trie<H, C> for TrieDB<'db, H, C> where
    H: Hasher,
    C: NodeCodec<H>, 
[src]

Return the root of the trie.

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

Returns a depth-first iterator over the elements of trie.

Is the trie empty?

Does the trie contain a given 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]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'db, H, C> Send for TrieDB<'db, H, C> where
    C: Send,
    <H as Hasher>::Out: Sync

impl<'db, H, C> Sync for TrieDB<'db, H, C> where
    C: Sync,
    <H as Hasher>::Out: Sync