[−][src]Struct trie_db::triedbmut::TrieDBMut
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 trie_db; extern crate reference_trie; extern crate hash_db; extern crate keccak_hasher; extern crate memory_db; use hash_db::Hasher; use reference_trie::{RefTrieDBMut, TrieMut}; use trie_db::DBValue; use keccak_hasher::KeccakHasher; use memory_db::*; fn main() { let mut memdb = MemoryDB::<KeccakHasher, HashKey<_>, DBValue>::default(); let mut root = Default::default(); let mut t = RefTrieDBMut::new(&mut memdb, &mut root); assert!(t.is_empty()); assert_eq!(*t.root(), KeccakHasher::hash(&[0u8][..])); 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]
H: Hasher,
C: NodeCodec<H>,
pub fn new(db: &'a mut dyn HashDB<H, DBValue>, root: &'a mut H::Out) -> Self
[src]
Create a new trie with backing database db
and empty root
.
pub fn from_existing(
db: &'a mut dyn HashDB<H, DBValue>,
root: &'a mut H::Out
) -> Result<Self, H::Out, C::Error>
[src]
db: &'a mut dyn HashDB<H, DBValue>,
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 if
root` does not exist.
pub fn db(&self) -> &dyn HashDB<H, DBValue>
[src]
Get the backing database.
pub fn db_mut(&mut self) -> &mut dyn HashDB<H, DBValue>
[src]
Get the backing database mutably.
pub fn commit(&mut self)
[src]
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]
H: Hasher,
C: NodeCodec<H>,
fn root(&mut self) -> &H::Out
[src]
fn is_empty(&self) -> bool
[src]
fn get<'x, 'key>(
&'x self,
key: &'key [u8]
) -> Result<Option<DBValue>, H::Out, C::Error> where
'x: 'key,
[src]
&'x self,
key: &'key [u8]
) -> Result<Option<DBValue>, H::Out, C::Error> where
'x: 'key,
fn insert(
&mut self,
key: &[u8],
value: &[u8]
) -> Result<Option<DBValue>, H::Out, C::Error>
[src]
&mut self,
key: &[u8],
value: &[u8]
) -> Result<Option<DBValue>, H::Out, C::Error>
fn remove(&mut self, key: &[u8]) -> Result<Option<DBValue>, H::Out, C::Error>
[src]
fn contains(&self, key: &[u8]) -> Result<bool, H::Out, C::Error>
[src]
Does the trie contain a given key?
impl<'a, H, C> Drop for TrieDBMut<'a, H, C> where
H: Hasher,
C: NodeCodec<H>,
[src]
H: Hasher,
C: NodeCodec<H>,
Auto Trait Implementations
impl<'a, H, C> Send for TrieDBMut<'a, H, C> where
C: Send,
<H as Hasher>::Out: Send,
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,
C: Sync,
<H as Hasher>::Out: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,