Struct patricia_trie::triedbmut::TrieDBMut [−][src]
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 hashdb::DBValue; use keccak_hasher::KeccakHasher; use memorydb::*; use ethereum_types::H256; fn main() { let mut memdb = MemoryDB::<KeccakHasher>::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]
impl<'a, H, C> TrieDBMut<'a, H, C> where
H: Hasher,
C: NodeCodec<H>, pub fn new(db: &'a mut HashDB<H>, root: &'a mut H::Out) -> Self[src]
pub fn new(db: &'a mut HashDB<H>, root: &'a mut H::Out) -> SelfCreate a new trie with backing database db and empty root.
pub fn from_existing(
db: &'a mut HashDB<H>,
root: &'a mut H::Out
) -> Result<Self, H::Out, C::Error>[src]
pub fn from_existing(
db: &'a mut HashDB<H>,
root: &'a mut H::Out
) -> Result<Self, H::Out, C::Error>Create a new trie with the backing database db and root. Returns an error ifroot` does not exist.
pub fn db(&self) -> &HashDB<H>[src]
pub fn db(&self) -> &HashDB<H>Get the backing database.
pub fn db_mut(&mut self) -> &mut HashDB<H>[src]
pub fn db_mut(&mut self) -> &mut HashDB<H>Get the backing database mutably.
pub fn commit(&mut self)[src]
pub fn commit(&mut self)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]
impl<'a, H, C> TrieMut<H, C> for TrieDBMut<'a, H, C> where
H: Hasher,
C: NodeCodec<H>, fn root(&mut self) -> &H::Out[src]
fn root(&mut self) -> &H::OutReturn the root of the trie.
fn is_empty(&self) -> bool[src]
fn is_empty(&self) -> boolIs the trie empty?
fn get<'x, 'key>(
&'x self,
key: &'key [u8]
) -> Result<Option<DBValue>, H::Out, C::Error> where
'x: 'key, [src]
fn get<'x, 'key>(
&'x self,
key: &'key [u8]
) -> Result<Option<DBValue>, H::Out, C::Error> 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>, H::Out, C::Error>[src]
fn insert(
&mut self,
key: &[u8],
value: &[u8]
) -> Result<Option<DBValue>, H::Out, C::Error>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>, H::Out, C::Error>[src]
fn remove(&mut self, key: &[u8]) -> Result<Option<DBValue>, H::Out, C::Error>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, H::Out, C::Error>[src]
fn contains(&self, key: &[u8]) -> Result<bool, H::Out, C::Error>Does the trie contain a given key?
impl<'a, H, C> Drop for TrieDBMut<'a, H, C> where
H: Hasher,
C: NodeCodec<H>, [src]
impl<'a, H, C> Drop for TrieDBMut<'a, H, C> where
H: Hasher,
C: NodeCodec<H>,