Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TreeHashMut #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@
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 @@
}
}

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

Check warning on line 159 in tree_hash/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

tree_hash/src/lib.rs#L158-L159

Added lines #L158 - L159 were not covered by tests
}

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

Check warning on line 163 in tree_hash/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

tree_hash/src/lib.rs#L162-L163

Added lines #L162 - L163 were not covered by tests
}

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

Check warning on line 167 in tree_hash/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

tree_hash/src/lib.rs#L166-L167

Added lines #L166 - L167 were not covered by tests
}

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

Check warning on line 171 in tree_hash/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

tree_hash/src/lib.rs#L170-L171

Added lines #L170 - L171 were not covered by tests
}
}

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