Trait Trie

Source
pub trait Trie<L: TrieLayout> {
    // Required methods
    fn root(&self) -> &TrieHash<L>;
    fn get_hash(
        &self,
        key: &[u8],
    ) -> Result<Option<TrieHash<L>>, TrieHash<L>, CError<L>>;
    fn get_with<Q: Query<L::Hash>>(
        &self,
        key: &[u8],
        query: Q,
    ) -> Result<Option<Q::Item>, TrieHash<L>, CError<L>>;
    fn lookup_first_descendant(
        &self,
        key: &[u8],
    ) -> Result<Option<MerkleValue<TrieHash<L>>>, TrieHash<L>, CError<L>>;
    fn iter<'a>(
        &'a self,
    ) -> Result<Box<dyn TrieIterator<L, Item = TrieItem<TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>;
    fn key_iter<'a>(
        &'a self,
    ) -> Result<Box<dyn TrieIterator<L, Item = TrieKeyItem<TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn contains(&self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>> { ... }
    fn get(&self, key: &[u8]) -> Result<Option<DBValue>, TrieHash<L>, CError<L>> { ... }
}
Expand description

A key-value datastore implemented as a database-backed modified Merkle tree.

Required Methods§

Source

fn root(&self) -> &TrieHash<L>

Return the root of the trie.

Source

fn get_hash( &self, key: &[u8], ) -> Result<Option<TrieHash<L>>, TrieHash<L>, CError<L>>

Returns the hash of the value for key.

Source

fn get_with<Q: Query<L::Hash>>( &self, key: &[u8], query: Q, ) -> Result<Option<Q::Item>, TrieHash<L>, CError<L>>

Search for the key with the given query parameter. See the docs of the Query trait for more details.

Source

fn lookup_first_descendant( &self, key: &[u8], ) -> Result<Option<MerkleValue<TrieHash<L>>>, TrieHash<L>, CError<L>>

Look up the MerkleValue of the node that is the closest descendant for the provided key.

When the provided key leads to a node, then the merkle value of that node is returned. However, if the key does not lead to a node, then the merkle value of the closest descendant is returned. None if no such descendant exists.

Source

fn iter<'a>( &'a self, ) -> Result<Box<dyn TrieIterator<L, Item = TrieItem<TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>

Returns a depth-first iterator over the elements of trie.

Source

fn key_iter<'a>( &'a self, ) -> Result<Box<dyn TrieIterator<L, Item = TrieKeyItem<TrieHash<L>, CError<L>>> + 'a>, TrieHash<L>, CError<L>>

Returns a depth-first iterator over the keys of elemets of trie.

Provided Methods§

Source

fn is_empty(&self) -> bool

Is the trie empty?

Source

fn contains(&self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>>

Does the trie contain a given key?

Source

fn get(&self, key: &[u8]) -> Result<Option<DBValue>, TrieHash<L>, CError<L>>

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'db, 'cache, L> Trie<L> for SecTrieDB<'db, 'cache, L>
where L: TrieLayout,

Source§

impl<'db, 'cache, L> Trie<L> for FatDB<'db, 'cache, L>
where L: TrieLayout,

Source§

impl<'db, 'cache, L> Trie<L> for TrieDB<'db, 'cache, L>
where L: TrieLayout,

Source§

impl<'db, 'cache, L: TrieLayout> Trie<L> for TrieKinds<'db, 'cache, L>