From 78e98bd32825981a0fc601c8d7bc7ad9715fbdce Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Thu, 18 Apr 2024 15:10:06 -0500 Subject: [PATCH] lib: add `[T; N]` instance for `ContentHash` Natural extension of the existing `[T]` instance. Signed-off-by: Austin Seipp Change-Id: Ib7f6fd829096b2cac8e3d7b9471a92ddb76a621b --- lib/src/content_hash.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/src/content_hash.rs b/lib/src/content_hash.rs index 4738697680..7e49ddaa82 100644 --- a/lib/src/content_hash.rs +++ b/lib/src/content_hash.rs @@ -79,6 +79,15 @@ impl ContentHash for [T] { } } +impl 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 ContentHash for Vec { fn hash(&self, state: &mut impl DigestUpdate) { self.as_slice().hash(state)