Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tree_hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ pub trait TreeHash {
fn tree_hash_root(&self) -> Hash256;
}

pub trait TreeHashMut {
fn tree_hash_type_mut() -> TreeHashType;

fn tree_hash_packed_encoding_mut(&self) -> PackedEncoding;

fn tree_hash_packing_factor_mut() -> usize;

fn tree_hash_root_mut(&mut self) -> Hash256;
}

/// Punch through references.
impl<'a, T> TreeHash for &'a T
where
Expand All @@ -141,6 +151,27 @@ where
}
}

impl<T> TreeHashMut for T
where
T: TreeHash,
{
fn tree_hash_type_mut() -> TreeHashType {
<T as TreeHash>::tree_hash_type()
}

fn tree_hash_packed_encoding_mut(&self) -> PackedEncoding {
<T as TreeHash>::tree_hash_packed_encoding(self)
}

fn tree_hash_packing_factor_mut() -> usize {
<T as TreeHash>::tree_hash_packing_factor()
}

fn tree_hash_root_mut(&mut self) -> Hash256 {
<T as TreeHash>::tree_hash_root(self)
}
}

#[macro_export]
macro_rules! tree_hash_ssz_encoding_as_vector {
($type: ident) => {
Expand Down