merkle-tree: Make instantiation a little less painful (#5037)

automerge
This commit is contained in:
Trent Nelson
2019-07-11 16:15:08 -06:00
committed by Grimes
parent 5b95685e12
commit 5698d48dc8
2 changed files with 4 additions and 3 deletions

View File

@ -84,7 +84,7 @@ impl MerkleTree {
capacity
}
pub fn new(items: &[&[u8]]) -> Self {
pub fn new<T: AsRef<[u8]>>(items: &[T]) -> Self {
let cap = MerkleTree::calculate_vec_capacity(items.len());
let mut mt = MerkleTree {
leaf_count: items.len(),
@ -92,6 +92,7 @@ impl MerkleTree {
};
for item in items {
let item = item.as_ref();
let hash = hash_leaf!(item);
mt.nodes.push(hash);
}
@ -178,7 +179,7 @@ mod tests {
#[test]
fn test_tree_from_empty() {
let mt = MerkleTree::new(&[]);
let mt = MerkleTree::new::<[u8; 0]>(&[]);
assert_eq!(mt.get_root(), None);
}