Type Definition patricia_trie_vapory::TrieDBMut[][src]

type TrieDBMut<'db> = TrieDBMut<'db, Layout>;

Convenience type alias to instantiate a Keccak/Rlp-flavoured TrieDBMut

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 tetsy_trie_db as trie;
extern crate patricia_trie_vapory as vaptrie;
extern crate tetsy_hash_db;
extern crate tetsy_keccak_hash;
extern crate tetsy_keccak_hasher;
extern crate tetsy_memory_db;
extern crate vapory_types;
extern crate elastic_array;
extern crate journaldb;

use tetsy_keccak_hash::KECCAK_NULL_RLP;
use vaptrie::{TrieDBMut, trie::TrieMut};
use tetsy_keccak_hasher::KeccakHasher;
use tetsy_memory_db::*;
use vapory_types::H256;
use elastic_array::ElasticArray128;
use trie::Trie;

type DBValue = ElasticArray128<u8>;

fn main() {
  let mut memdb = journaldb::new_tetsy_memory_db();
  let mut root = H256::zero();
  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(), b"bar".to_vec());
  t.remove(b"foo").unwrap();
  assert!(!t.contains(b"foo").unwrap());
}