Skip to content

Commit a4f944c

Browse files
Seulgi Kimsgkim126
authored andcommitted
Make TrieMut a subtype of Trie
This commit makes Trie have immutable methods and TrieMut have mutable methods.
1 parent 0e3c840 commit a4f944c

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

util/merkle/src/lib.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,8 @@ pub trait Trie {
8484
fn get(&self, key: &[u8]) -> Result<Option<DBValue>>;
8585
}
8686

87-
/// A key-value datastore implemented as a database-backed Merkle trie.
88-
pub trait TrieMut {
89-
/// Return the root of the trie.
90-
fn root(&self) -> &H256;
91-
92-
/// Is the trie empty?
93-
fn is_empty(&self) -> bool;
94-
95-
/// Does the trie contain a given key?
96-
fn contains(&self, key: &[u8]) -> Result<bool> {
97-
self.get(key).map(|x| x.is_some())
98-
}
99-
100-
/// What is the value of the given key in this trie?
101-
fn get(&self, key: &[u8]) -> Result<Option<DBValue>>;
102-
87+
/// A key-value datastore implemented as a database-backed modified Merkle tree.
88+
pub trait TrieMut: Trie {
10389
/// Insert a `key`/`value` pair into the trie. An empty value is equivalent to removing
10490
/// `key` from the trie. Returns the old value associated with this key, if it existed.
10591
fn insert(&mut self, key: &[u8], value: &[u8]) -> Result<Option<DBValue>>;

util/merkle/src/triedbmut.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl<'a> fmt::Display for RlpNode<'a> {
297297
}
298298
}
299299

300-
impl<'a> TrieMut for TrieDBMut<'a> {
300+
impl<'a> Trie for TrieDBMut<'a> {
301301
fn root(&self) -> &H256 {
302302
self.root
303303
}
@@ -311,7 +311,9 @@ impl<'a> TrieMut for TrieDBMut<'a> {
311311

312312
t.get(key)
313313
}
314+
}
314315

316+
impl<'a> TrieMut for TrieDBMut<'a> {
315317
fn insert(&mut self, key: &[u8], value: &[u8]) -> crate::Result<Option<DBValue>> {
316318
let path = blake256(key);
317319
let mut old_val = None;

0 commit comments

Comments
 (0)