Skip to content

Commit

Permalink
lib: add [T; N] instance for ContentHash
Browse files Browse the repository at this point in the history
Natural extension of the existing `[T]` instance.

Signed-off-by: Austin Seipp <[email protected]>
Change-Id: Ib7f6fd829096b2cac8e3d7b9471a92ddb76a621b
  • Loading branch information
thoughtpolice committed Oct 19, 2024
1 parent 0ec426d commit 0e4b412
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/src/content_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ impl<T: ContentHash> ContentHash for [T] {
}
}

impl<T: ContentHash, const N: usize> ContentHash for [T; N] {
fn hash(&self, state: &mut impl DigestUpdate) {
state.update(&(N as u64).to_le_bytes());
for x in self {
x.hash(state);
}
}
}

impl<T: ContentHash> ContentHash for Vec<T> {
fn hash(&self, state: &mut impl DigestUpdate) {
self.as_slice().hash(state);
Expand Down

0 comments on commit 0e4b412

Please sign in to comment.