Struct patricia_trie::triedbmut::TrieDBMut[][src]

pub struct TrieDBMut<'a, H, C> where
    H: Hasher + 'a,
    C: NodeCodec<H>, 
{ /* fields omitted */ }

A Trie implementation using a generic HashDB backing database.

Use it as a TrieMut trait object. You can use db() to get the backing database object. Note that changes are not committed to the database until commit is called. Querying the root or dropping the trie will commit automatically.

Example

extern crate patricia_trie as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate hashdb;
extern crate keccak_hash;
extern crate keccak_hasher;
extern crate memorydb;
extern crate ethereum_types;

use keccak_hash::KECCAK_NULL_RLP;
use ethtrie::{TrieDBMut, trie::TrieMut};
use trie::DBValue;
use keccak_hasher::KeccakHasher;
use memorydb::*;
use ethereum_types::H256;

fn main() {
  let mut memdb = MemoryDB::<KeccakHasher, DBValue>::new();
  let mut root = H256::new();
  let mut t = TrieDBMut::new(&mut memdb, &mut root);
  assert!(t.is_empty());
  assert_eq!(*t.root(), KECCAK_NULL_RLP);
  t.insert(b"foo", b"bar").unwrap();
  assert!(t.contains(b"foo").unwrap());
  assert_eq!(t.get(b"foo").unwrap().unwrap(), DBValue::from_slice(b"bar"));
  t.remove(b"foo").unwrap();
  assert!(!t.contains(b"foo").unwrap());
}

Methods

impl<'a, H, C> TrieDBMut<'a, H, C> where
    H: Hasher,
    C: NodeCodec<H>, 
[src]

Create a new trie with backing database db and empty root.

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

Get the backing database.

Get the backing database mutably.

Commit the in-memory changes to disk, freeing their storage and updating the state root.

Trait Implementations

impl<'a, H, C> TrieMut<H, C> for TrieDBMut<'a, H, C> where
    H: Hasher,
    C: NodeCodec<H>, 
[src]

Return the root of the trie.

Is the trie empty?

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

Insert a key/value pair into the trie. An empty value is equivalent to removing key from the trie. Returns the old value associated with this key, if it existed. Read more

Remove a key from the trie. Equivalent to making it equal to the empty value. Returns the old value associated with this key, if it existed. Read more

Does the trie contain a given key?

impl<'a, H, C> Drop for TrieDBMut<'a, H, C> where
    H: Hasher,
    C: NodeCodec<H>, 
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl<'a, H, C> Send for TrieDBMut<'a, H, C> where
    C: Send,
    <H as Hasher>::Out: Send

impl<'a, H, C> Sync for TrieDBMut<'a, H, C> where
    C: Sync,
    <H as Hasher>::Out: Sync