Skip to content

Commit

Permalink
Switch to &mut self
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr committed Nov 19, 2021
1 parent 67891cd commit 5ddba5d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions trie-db/src/fatdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ where
{
fn root(&self) -> &TrieHash<L> { self.raw.root() }

fn contains(&self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>> {
fn contains(&mut self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>> {
self.raw.contains(L::Hash::hash(key).as_ref())
}

fn get_with<'a, 'key, Q: Query<L::Hash>>(&'a self, key: &'key [u8], query: Q)
fn get_with<'a, 'key, Q: Query<L::Hash>>(&'a mut self, key: &'key [u8], query: Q)
-> Result<Option<Q::Item>, TrieHash<L>, CError<L>>
where 'a: 'key
{
Expand Down
25 changes: 17 additions & 8 deletions trie-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ pub trait Trie<L: TrieLayout> {
fn is_empty(&self) -> bool { *self.root() == L::Codec::hashed_null_node() }

/// Does the trie contain a given key?
fn contains(&self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>> {
self.get(key).map(|x| x.is_some() )
fn contains(&mut self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>> {
self.get(key).map(|x| x.is_some())
}

/// What is the value of the given key in this trie?
fn get<'a, 'key>(
&'a self,
&'a mut self,
key: &'key [u8],
) -> Result<Option<DBValue>, TrieHash<L>, CError<L>> where 'a: 'key {
self.get_with(key, |v: &[u8]| v.to_vec() )
Expand All @@ -193,7 +193,7 @@ pub trait Trie<L: TrieLayout> {
/// Search for the key with the given query parameter. See the docs of the `Query`
/// trait for more details.
fn get_with<'a, 'key, Q: Query<L::Hash>>(
&'a self,
&'a mut self,
key: &'key [u8],
query: Q
) -> Result<Option<Q::Item>, TrieHash<L>, CError<L>> where 'a: 'key;
Expand Down Expand Up @@ -300,17 +300,26 @@ impl<'db, L: TrieLayout> Trie<L> for TrieKinds<'db, L> {
wrapper!(self, is_empty,)
}

fn contains(&self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>> {
wrapper!(self, contains, key)
fn contains(&mut self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>> {
match self {
TrieKinds::Generic(ref mut t) => t.contains(key),
TrieKinds::Secure(ref mut t) => t.contains(key),
TrieKinds::Fat(ref mut t) => t.contains(key),
}
}

fn get_with<'a, 'key, Q: Query<L::Hash>>(
&'a self, key: &'key [u8],
&'a mut self,
key: &'key [u8],
query: Q,
) -> Result<Option<Q::Item>, TrieHash<L>, CError<L>>
where 'a: 'key
{
wrapper!(self, get_with, key, query)
match self {
TrieKinds::Generic(ref mut t) => t.get_with(key, query),
TrieKinds::Secure(ref mut t) => t.get_with(key, query),
TrieKinds::Fat(ref mut t) => t.get_with(key, query),
}
}

fn iter<'a>(&'a self) -> Result<
Expand Down
2 changes: 1 addition & 1 deletion trie-db/src/proof/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<'a, C: NodeCodec> StackEntry<'a, C> {
/// Generate a compact proof for key-value pairs in a trie given a set of keys.
///
/// Assumes inline nodes have only inline children.
pub fn generate_proof<'a, T, L, I, K>(trie: &T, keys: I)
pub fn generate_proof<'a, T, L, I, K>(trie: &mut T, keys: I)
-> TrieResult<Vec<Vec<u8>>, TrieHash<L>, CError<L>>
where
T: Trie<L>,
Expand Down
4 changes: 2 additions & 2 deletions trie-db/src/sectriedb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ where
{
fn root(&self) -> &TrieHash<L> { self.raw.root() }

fn contains(&self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>> {
fn contains(&mut self, key: &[u8]) -> Result<bool, TrieHash<L>, CError<L>> {
self.raw.contains(L::Hash::hash(key).as_ref())
}

fn get_with<'a, 'key, Q: Query<L::Hash>>(
&'a self,
&'a mut self,
key: &'key [u8],
query: Q,
) -> Result<Option<Q::Item>, TrieHash<L>, CError<L>>
Expand Down
2 changes: 1 addition & 1 deletion trie-db/src/triedb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ where
fn root(&self) -> &TrieHash<L> { self.root }

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

0 comments on commit 5ddba5d

Please sign in to comment.