Skip to content

Commit 04fab01

Browse files
committed
fix: qualify Hash trait in macros for --no-default-features
Uses fully qualified syntax `<T as $crate::Hash>::method()` instead of relying on the `Hash` trait being in scope. This ensures `hash_newtype!` macros compile correctly when used with `--no-default-features` in CI overhaul PR #253.
1 parent 3884314 commit 04fab01

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

hashes/src/util.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ macro_rules! hash_newtype {
229229
/// Reverses the bytes of the hash
230230
#[allow(unused)]
231231
pub fn reverse(&self) -> Self {
232-
let mut reversed_bytes = self.0.to_byte_array();
232+
let mut reversed_bytes = <$hash as $crate::Hash>::to_byte_array(self.0);
233233
reversed_bytes.reverse();
234-
Self::from_byte_array(reversed_bytes)
234+
<Self as $crate::Hash>::from_byte_array(reversed_bytes)
235235
}
236236
}
237237

@@ -275,17 +275,17 @@ macro_rules! hash_newtype {
275275

276276
#[inline]
277277
fn to_byte_array(self) -> Self::Bytes {
278-
self.0.to_byte_array()
278+
<$hash as $crate::Hash>::to_byte_array(self.0)
279279
}
280280

281281
#[inline]
282282
fn as_byte_array(&self) -> &Self::Bytes {
283-
self.0.as_byte_array()
283+
<$hash as $crate::Hash>::as_byte_array(&self.0)
284284
}
285285

286286
#[inline]
287287
fn all_zeros() -> Self {
288-
let zeros = <$hash>::all_zeros();
288+
let zeros = <$hash as $crate::Hash>::all_zeros();
289289
$newtype(zeros)
290290
}
291291
}
@@ -294,14 +294,13 @@ macro_rules! hash_newtype {
294294
type Err = $crate::hex::Error;
295295
fn from_str(s: &str) -> $crate::_export::_core::result::Result<$newtype, Self::Err> {
296296
use $crate::hex::{HexIterator, FromHex};
297-
use $crate::Hash;
298297

299-
let inner: <$hash as Hash>::Bytes = if <Self as $crate::Hash>::DISPLAY_BACKWARD {
298+
let inner: <$hash as $crate::Hash>::Bytes = if <Self as $crate::Hash>::DISPLAY_BACKWARD {
300299
FromHex::from_byte_iter(HexIterator::new(s)?.rev())?
301300
} else {
302301
FromHex::from_byte_iter(HexIterator::new(s)?)?
303302
};
304-
Ok($newtype(<$hash>::from_byte_array(inner)))
303+
Ok($newtype(<$hash as $crate::Hash>::from_byte_array(inner)))
305304
}
306305
}
307306

@@ -321,7 +320,7 @@ macro_rules! hash_newtype {
321320
}
322321

323322
impl From<[u8; <$hash as $crate::Hash>::LEN]> for $newtype {
324-
fn from(bytes: [u8; <$hash as Hash>::LEN]) -> Self {
323+
fn from(bytes: [u8; <$hash as $crate::Hash>::LEN]) -> Self {
325324
$newtype(<$hash as $crate::Hash>::from_byte_array(bytes))
326325
}
327326
}
@@ -410,17 +409,17 @@ macro_rules! hash_newtype_no_ord {
410409

411410
#[inline]
412411
fn to_byte_array(self) -> Self::Bytes {
413-
self.0.to_byte_array()
412+
<$hash as $crate::Hash>::to_byte_array(self.0)
414413
}
415414

416415
#[inline]
417416
fn as_byte_array(&self) -> &Self::Bytes {
418-
self.0.as_byte_array()
417+
<$hash as $crate::Hash>::as_byte_array(&self.0)
419418
}
420419

421420
#[inline]
422421
fn all_zeros() -> Self {
423-
let zeros = <$hash>::all_zeros();
422+
let zeros = <$hash as $crate::Hash>::all_zeros();
424423
$newtype(zeros)
425424
}
426425
}
@@ -429,14 +428,13 @@ macro_rules! hash_newtype_no_ord {
429428
type Err = $crate::hex::Error;
430429
fn from_str(s: &str) -> $crate::_export::_core::result::Result<$newtype, Self::Err> {
431430
use $crate::hex::{HexIterator, FromHex};
432-
use $crate::Hash;
433431

434-
let inner: <$hash as Hash>::Bytes = if <Self as $crate::Hash>::DISPLAY_BACKWARD {
432+
let inner: <$hash as $crate::Hash>::Bytes = if <Self as $crate::Hash>::DISPLAY_BACKWARD {
435433
FromHex::from_byte_iter(HexIterator::new(s)?.rev())?
436434
} else {
437435
FromHex::from_byte_iter(HexIterator::new(s)?)?
438436
};
439-
Ok($newtype(<$hash>::from_byte_array(inner)))
437+
Ok($newtype(<$hash as $crate::Hash>::from_byte_array(inner)))
440438
}
441439
}
442440

@@ -456,7 +454,7 @@ macro_rules! hash_newtype_no_ord {
456454
}
457455

458456
impl From<[u8; <$hash as $crate::Hash>::LEN]> for $newtype {
459-
fn from(bytes: [u8; <$hash as Hash>::LEN]) -> Self {
457+
fn from(bytes: [u8; <$hash as $crate::Hash>::LEN]) -> Self {
460458
$newtype(<$hash as $crate::Hash>::from_byte_array(bytes))
461459
}
462460
}

0 commit comments

Comments
 (0)