# Struct ethcore_util::trie::triedbmut::TrieDBMut [−] [src]

    pub struct TrieDBMut<'a> {
        pub hash_count: usize,
        // some 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 ethcore_util as util;

    use util::trie::*;
    use util::hashdb::*;
    use util::memorydb::*;
    use util::hash::*;

    fn main() {
      let mut memdb = MemoryDB::new();
      let mut root = H256::new();
      let mut t = TrieDBMut::new(&mut memdb, &mut root);
      assert!(t.is_empty());
      assert_eq!(*t.root(), ::util::sha3::SHA3_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());
    }

## Fields

`hash_count: usize`

The number of hash operations this trie has performed. Note that none are performed until changes are committed.

## Methods

### `impl<'a> TrieDBMut<'a>`
[src]

#### `fn new(db: &'a mut HashDB, root: &'a mut H256) -> Self`

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

#### `fn from_existing(db: &'a mut HashDB, root: &'a mut H256) -> Result<Self>`

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

#### `fn db(&self) -> &HashDB`

Get the backing database.

#### `fn db_mut(&mut self) -> &mut HashDB`

Get the backing database mutably.

#### `fn commit(&mut self)`

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

## Trait Implementations

### `impl<'a> TrieMut for TrieDBMut<'a>`
[src]

#### `fn root(&mut self) -> &H256`

Return the root of the trie.

#### `fn is_empty(&self) -> bool`

Is the trie empty?

#### `fn get<'x, 'key>(&'x self, key: &'key [u8]) -> Result<Option<DBValue>> where 'x: 'key`

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

#### `fn insert(&mut self, key: &[u8], value: &[u8]) -> Result<Option<DBValue>>`

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

#### `fn remove(&mut self, key: &[u8]) -> Result<Option<DBValue>>`

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

#### `fn contains(&self, key: &[u8]) -> Result<bool>`

Does the trie contain a given key?

### `impl<'a> Drop for TrieDBMut<'a>`
[src]

#### `fn drop(&mut self)`

A method called when the value goes out of scope. Read more

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)