diff --git a/hashes/src/sha256t.rs b/hashes/src/sha256t.rs index 1d72da43f..a315f7f32 100644 --- a/hashes/src/sha256t.rs +++ b/hashes/src/sha256t.rs @@ -53,7 +53,7 @@ impl Hash where (T,): Tag, { - fn internal_new(arr: [u8; 32]) -> Self { Hash(arr, PhantomData) } + const fn internal_new(arr: [u8; 32]) -> Self { Hash(arr, PhantomData) } /// Zero cost conversion between a fixed length byte array shared reference and /// a shared reference to this Hash type. @@ -110,13 +110,13 @@ where } /// Returns the underlying byte array. - pub fn to_byte_array(self) -> [u8; 32] { self.0 } + pub const fn to_byte_array(self) -> [u8; 32] { self.0 } /// Returns a reference to the underlying byte array. - pub fn as_byte_array(&self) -> &[u8; 32] { &self.0 } + pub const fn as_byte_array(&self) -> &[u8; 32] { &self.0 } /// Constructs a hash from the underlying byte array. - pub fn from_byte_array(bytes: [u8; 32]) -> Self { Self::internal_new(bytes) } + pub const fn from_byte_array(bytes: [u8; 32]) -> Self { Self::internal_new(bytes) } /// Returns an all zero hash. /// diff --git a/hashes/src/util.rs b/hashes/src/util.rs index f778f098f..fd9589e32 100644 --- a/hashes/src/util.rs +++ b/hashes/src/util.rs @@ -195,17 +195,17 @@ macro_rules! hash_newtype { #[allow(unused)] // Private wrapper types may not need all functions. impl $newtype { /// Creates this wrapper type from the inner hash type. - pub fn from_raw_hash(inner: $hash) -> $newtype { + pub const fn from_raw_hash(inner: $hash) -> $newtype { $newtype(inner) } /// Returns the inner hash (sha256, sh256d etc.). - pub fn to_raw_hash(self) -> $hash { + pub const fn to_raw_hash(self) -> $hash { self.0 } /// Returns a reference to the inner hash (sha256, sh256d etc.). - pub fn as_raw_hash(&self) -> &$hash { + pub const fn as_raw_hash(&self) -> &$hash { &self.0 } @@ -250,18 +250,18 @@ macro_rules! hash_newtype { } /// Returns the underlying byte array. - pub fn to_byte_array(self) -> <$hash as $crate::Hash>::Bytes { + pub const fn to_byte_array(self) -> <$hash as $crate::Hash>::Bytes { self.0.to_byte_array() } /// Returns a reference to the underlying byte array. - pub fn as_byte_array(&self) -> &<$hash as $crate::Hash>::Bytes { + pub const fn as_byte_array(&self) -> &<$hash as $crate::Hash>::Bytes { self.0.as_byte_array() } /// Constructs a hash from the underlying byte array. - pub fn from_byte_array(bytes: <$hash as $crate::Hash>::Bytes) -> Self { - $newtype(<$hash as $crate::Hash>::from_byte_array(bytes)) + pub const fn from_byte_array(bytes: <$hash as $crate::Hash>::Bytes) -> Self { + $newtype(<$hash>::from_byte_array(bytes)) } /// Returns an all zero hash.