From bc6da1fe07937051ada4a60c78f5f5128484a91a Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Mon, 24 Mar 2025 13:19:59 +0100 Subject: [PATCH] Swap around the fields in `sha256t::Hash` There's a restriction that for structs containing unsized types the unsized type has to be the last field. `sha256t::Hash` is not an unsized type but we are going to introduce a macro that will assume this order to work equally well with both sized and unsized types. Thus we swap it upfront here. --- hashes/src/sha256t/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hashes/src/sha256t/mod.rs b/hashes/src/sha256t/mod.rs index d8eb32793..59f73bf0f 100644 --- a/hashes/src/sha256t/mod.rs +++ b/hashes/src/sha256t/mod.rs @@ -45,13 +45,13 @@ pub trait Tag { /// Output of the SHA256t hash function. #[repr(transparent)] -pub struct Hash([u8; 32], PhantomData); +pub struct Hash(PhantomData, [u8; 32]); impl Hash where T: Tag, { - const fn internal_new(arr: [u8; 32]) -> Self { Hash(arr, PhantomData) } + 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) } @@ -117,10 +117,10 @@ where } /// Returns the underlying byte array. - pub const fn to_byte_array(self) -> [u8; 32] { self.0 } + pub const fn to_byte_array(self) -> [u8; 32] { self.1 } /// Returns a reference to the underlying byte array. - pub const fn as_byte_array(&self) -> &[u8; 32] { &self.0 } + pub const fn as_byte_array(&self) -> &[u8; 32] { &self.1 } } impl Copy for Hash {}