units: Replace manual CompactTarget fmt traits with macro
What changed, and why it matters
This commit is a routine code cleanup. It replaces four hand-written formatting rules for the CompactTarget type with a single existing macro that does the same thing. There is no functional change and no security relevance.
No action needed; this is a non-security refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch removes manual implementations of LowerHex, UpperHex, Octal, and Binary for CompactTarget in units/src/pow.rs and instead invokes crate::internal_macros::impl_fmt_traits_for_u32_wrapper!(CompactTarget). The Display implementation and parse helper remain unchanged. The macro generates equivalent trait implementations, so behavior is preserved.
Changed components
units/src/pow.rsInspect captured patch +2 / −20
diff --git a/units/src/pow.rs b/units/src/pow.rs
index a73735c7..e1057795 100644
--- a/units/src/pow.rs
+++ b/units/src/pow.rs
@@ -77,31 +77,13 @@ impl CompactTarget {
}
}
+crate::internal_macros::impl_fmt_traits_for_u32_wrapper!(CompactTarget);
+
impl fmt::Display for CompactTarget {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
}
-impl fmt::LowerHex for CompactTarget {
- #[inline]
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(&self.0, f) }
-}
-
-impl fmt::UpperHex for CompactTarget {
- #[inline]
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::UpperHex::fmt(&self.0, f) }
-}
-
-impl fmt::Octal for CompactTarget {
- #[inline]
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Octal::fmt(&self.0, f) }
-}
-
-impl fmt::Binary for CompactTarget {
- #[inline]
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Binary::fmt(&self.0, f) }
-}
-
parse_int::impl_parse_str_from_int_infallible!(CompactTarget, u32, from_consensus);
#[cfg(feature = "encoding")]
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.