Struct tetsy_reference_trie::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
use tetsy_hash_db::Hasher; use tetsy_reference_trie::{RefTrieDBMut, TrieMut}; use tetsy_trie_db::DBValue; use tetsy_keccak_hasher::KeccakHasher; use tetsy_memory_db::*; 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(), b"bar".to_vec()); t.remove(b"foo").unwrap(); assert!(!t.contains(b"foo").unwrap());
Implementations
impl<'a, L> TrieDBMut<'a, L> where
L: TrieLayout,
[src]
L: TrieLayout,
pub fn new(
db: &'a mut (dyn HashDB<<L as TrieLayout>::Hash, Vec<u8, Global>> + 'a),
root: &'a mut <<L as TrieLayout>::Hash as Hasher>::Out
) -> TrieDBMut<'a, L>
[src]
db: &'a mut (dyn HashDB<<L as TrieLayout>::Hash, Vec<u8, Global>> + 'a),
root: &'a mut <<L as TrieLayout>::Hash as Hasher>::Out
) -> TrieDBMut<'a, L>
Create a new trie with backing database db
and empty root
.
pub fn from_existing(
db: &'a mut (dyn HashDB<<L as TrieLayout>::Hash, Vec<u8, Global>> + 'a),
root: &'a mut <<L as TrieLayout>::Hash as Hasher>::Out
) -> Result<TrieDBMut<'a, L>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>>
[src]
db: &'a mut (dyn HashDB<<L as TrieLayout>::Hash, Vec<u8, Global>> + 'a),
root: &'a mut <<L as TrieLayout>::Hash as Hasher>::Out
) -> Result<TrieDBMut<'a, L>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>>
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<<L as TrieLayout>::Hash, Vec<u8, Global>>
[src]
Get the backing database.
pub fn db_mut(
&mut self
) -> &mut dyn HashDB<<L as TrieLayout>::Hash, Vec<u8, Global>>
[src]
&mut self
) -> &mut dyn HashDB<<L as TrieLayout>::Hash, Vec<u8, Global>>
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, L> Drop for TrieDBMut<'a, L> where
L: TrieLayout,
[src]
L: TrieLayout,
impl<'a, L> TrieMut<L> for TrieDBMut<'a, L> where
L: TrieLayout,
[src]
L: TrieLayout,
pub fn root(&mut self) -> &<<L as TrieLayout>::Hash as Hasher>::Out
[src]
pub fn is_empty(&self) -> bool
[src]
pub fn get<'x, 'key>(
&'x self,
key: &'key [u8]
) -> Result<Option<Vec<u8, Global>>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>> where
'x: 'key,
[src]
&'x self,
key: &'key [u8]
) -> Result<Option<Vec<u8, Global>>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>> where
'x: 'key,
pub fn insert(
&mut self,
key: &[u8],
value: &[u8]
) -> Result<Option<Vec<u8, Global>>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>>
[src]
&mut self,
key: &[u8],
value: &[u8]
) -> Result<Option<Vec<u8, Global>>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>>
pub fn remove(
&mut self,
key: &[u8]
) -> Result<Option<Vec<u8, Global>>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>>
[src]
&mut self,
key: &[u8]
) -> Result<Option<Vec<u8, Global>>, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>>
pub fn contains(
&self,
key: &[u8]
) -> Result<bool, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>>
[src]
&self,
key: &[u8]
) -> Result<bool, Box<TrieError<<<L as TrieLayout>::Hash as Hasher>::Out, <<L as TrieLayout>::Codec as NodeCodec>::Error>, Global>>
Auto Trait Implementations
impl<'a, L> !RefUnwindSafe for TrieDBMut<'a, L>
impl<'a, L> Send for TrieDBMut<'a, L>
impl<'a, L> Sync for TrieDBMut<'a, L>
impl<'a, L> Unpin for TrieDBMut<'a, L> where
<<L as TrieLayout>::Hash as Hasher>::Out: Unpin,
<<L as TrieLayout>::Hash as Hasher>::Out: Unpin,
impl<'a, L> !UnwindSafe for TrieDBMut<'a, L>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,