From 57c77c3d8cac9ddb9f135bf0281b3c270ecefeb9 Mon Sep 17 00:00:00 2001 From: sinui0 <65924192+sinui0@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:15:26 +0900 Subject: [PATCH] add associated const SIZE to Hash --- src/hasher.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/hasher.rs b/src/hasher.rs index 52620c3..a652798 100644 --- a/src/hasher.rs +++ b/src/hasher.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use core::{convert::TryFrom, mem}; +use core::convert::TryFrom; /// This type is used as a hash type in the library. /// @@ -14,9 +14,14 @@ use core::{convert::TryFrom, mem}; /// `PartialEq` is required to compare equality when verifying proof /// `Into>` is required to be able to serialize proof /// `TryFrom>` is required to parse hashes from a serialized proof -pub trait Hash: Copy + PartialEq + Into> + TryFrom> {} +pub trait Hash: Copy + PartialEq + Into> + TryFrom> { + /// The size of the hash in bytes. + const SIZE: usize; +} -impl Hash for T where T: Copy + PartialEq + Into> + TryFrom> {} +impl Hash for [u8; N] { + const SIZE: usize = N; +} /// Hasher is a trait used to provide a hashing algorithm for the library. /// @@ -72,11 +77,4 @@ pub trait Hasher: Clone { None => *left, } } - - /// Returns the byte size of `Self::Hash`. Default implementation returns - /// `mem::size_of::()`. Usually doesn't need to be overridden. - /// Used internally by `MerkleProof` to parse hashes from a serialized proof. - fn hash_size() -> usize { - mem::size_of::() - } }