Struct patricia_trie::triedb::TrieDB  [−][src]
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>::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] 
impl<'db, H, C> TrieDB<'db, H, C> where
    H: Hasher,
    C: NodeCodec<H>, pub fn new(
    db: &'db HashDB<H>, 
    root: &'db H::Out
) -> Result<Self, H::Out, C::Error>[src] 
pub fn new(
    db: &'db HashDB<H>, 
    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 HashDB<H>[src] 
pub fn db(&'db self) -> &'db HashDB<H>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] 
impl<'db, H, C> Trie<H, C> for TrieDB<'db, H, C> where
    H: Hasher,
    C: NodeCodec<H>, fn root(&self) -> &H::Out[src] 
fn root(&self) -> &H::OutReturn the root of the trie.
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] 
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, Search for the key with the given query parameter. See the docs of the Query trait for more details. Read more
fn iter<'a>(
    &'a self
) -> Result<Box<TrieIterator<H, C, Item = TrieItem<H::Out, C::Error>> + 'a>, H::Out, C::Error>[src] 
fn iter<'a>(
    &'a self
) -> Result<Box<TrieIterator<H, C, Item = TrieItem<H::Out, C::Error>> + 'a>, H::Out, C::Error>Returns a depth-first iterator over the elements of trie.
fn is_empty(&self) -> bool[src] 
fn is_empty(&self) -> boolIs the trie empty?
fn contains(&self, key: &[u8]) -> Result<bool, H::Out, C::Error>[src] 
fn contains(&self, key: &[u8]) -> Result<bool, H::Out, C::Error>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] 
fn get<'a, 'key>(
    &'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] 
impl<'db, H, C> Debug for TrieDB<'db, H, C> where
    H: Hasher,
    C: NodeCodec<H>,