From a5d96ceb3965f684d7a58fcb8b25ca926b3b555b Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Mon, 5 May 2025 16:22:58 +0000 Subject: [PATCH] hashes: remove private `internal_new` method This method is used to implement `from_byte_array`. But there is no need for the method to exist. We can just inline it in `from_byte_array` and reduce the amount of indirection in our macros. Also make the same change in sha256t. --- hashes/src/internal_macros.rs | 8 ++------ hashes/src/sha256t/mod.rs | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/hashes/src/internal_macros.rs b/hashes/src/internal_macros.rs index f0f410167..f3d2cecfb 100644 --- a/hashes/src/internal_macros.rs +++ b/hashes/src/internal_macros.rs @@ -130,12 +130,8 @@ macro_rules! hash_type_no_default { } impl Hash { - const fn internal_new(arr: [u8; $bits / 8]) -> Self { Hash(arr) } - /// Constructs a new hash from the underlying byte array. - pub const fn from_byte_array(bytes: [u8; $bits / 8]) -> Self { - Self::internal_new(bytes) - } + pub const fn from_byte_array(bytes: [u8; $bits / 8]) -> Self { Hash(bytes) } /// Copies a byte slice into a hash object. #[deprecated(since = "0.15.0", note = "use `from_byte_array` instead")] @@ -151,7 +147,7 @@ macro_rules! hash_type_no_default { } else { let mut ret = [0; $bits / 8]; ret.copy_from_slice(sl); - Ok(Self::internal_new(ret)) + Ok(Self::from_byte_array(ret)) } } diff --git a/hashes/src/sha256t/mod.rs b/hashes/src/sha256t/mod.rs index 6b38aaee4..5b6d91db6 100644 --- a/hashes/src/sha256t/mod.rs +++ b/hashes/src/sha256t/mod.rs @@ -62,10 +62,8 @@ impl Hash where T: Tag, { - const fn internal_new(arr: [u8; 32]) -> Self { Hash(PhantomData, arr) } - /// Constructs a new hash from the underlying byte array. - pub const fn from_byte_array(bytes: [u8; 32]) -> Self { Self::internal_new(bytes) } + pub const fn from_byte_array(bytes: [u8; 32]) -> Self { Self(PhantomData, bytes) } /// Copies a byte slice into a hash object. #[deprecated(since = "0.15.0", note = "use `from_byte_array` instead")]