What changed, and why it matters
This commit simply moves two code blocks around within a single file. It is a cosmetic reorganization with no functional changes, no bug fixes, and no security implications.
No action needed. This is a non-functional code-style refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit rearranges the hex_codec.rs module so that HexPrimitive appears near the top and ParsePrimitiveError appears near the bottom. The diff shows identical code content moved to new line positions; there are no logic, signature, visibility, or behavior changes.
Changed components
primitives/src/hex_codec.rsInspect captured patch +47 / −47
diff --git a/primitives/src/hex_codec.rs b/primitives/src/hex_codec.rs
index a0b53524..075ef05b 100644
--- a/primitives/src/hex_codec.rs
+++ b/primitives/src/hex_codec.rs
@@ -15,53 +15,6 @@ use encoding::{Decodable, Decoder, Encodable, EncodableByteIter};
use hex_unstable::{BytesToHexIter, Case};
use internals::write_err;
-/// An error type for errors that can occur during parsing of a `Decodable` type from hex.
-pub(crate) enum ParsePrimitiveError<T: Decodable> {
- /// Tried to decode an odd length string
- OddLengthString(hex_unstable::OddLengthStringError),
- /// Encountered an invalid hex character
- InvalidChar(hex_unstable::InvalidCharError),
- /// A decode error from `consensus_encoding`
- Decode(<T::Decoder as Decoder>::Error),
-}
-
-impl<T: Decodable> fmt::Debug for ParsePrimitiveError<T> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- Self::OddLengthString(ref e) => write_err!(f, "odd length string"; e),
- Self::InvalidChar(ref e) => write_err!(f, "invalid character"; e),
- Self::Decode(_) => write!(f, "failure decoding hex string into {}", core::any::type_name::<T>()),
- }
- }
-}
-
-impl<T: Decodable> fmt::Display for ParsePrimitiveError<T> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self, f) }
-}
-
-impl<T: Decodable> From<hex_unstable::OddLengthStringError> for ParsePrimitiveError<T> {
- fn from(err: hex_unstable::OddLengthStringError) -> Self { Self::OddLengthString(err) }
-}
-
-impl<T: Decodable> From<hex_unstable::InvalidCharError> for ParsePrimitiveError<T> {
- fn from(err: hex_unstable::InvalidCharError) -> Self { Self::InvalidChar(err) }
-}
-
-impl<T: Decodable> From<core::convert::Infallible> for ParsePrimitiveError<T> {
- fn from(never: core::convert::Infallible) -> Self { match never {} }
-}
-
-#[cfg(feature = "std")]
-impl<T: Decodable> std::error::Error for ParsePrimitiveError<T> {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- Self::OddLengthString(ref e) => Some(e),
- Self::InvalidChar(ref e) => Some(e),
- Self::Decode(_) => None,
- }
- }
-}
-
/// Hex encoding wrapper type for Encodable + Decodable types.
///
/// Provides default implementations for `Display`, `Debug`, `LowerHex`, and `UpperHex`.
@@ -198,6 +151,53 @@ impl<T: Encodable + Decodable> fmt::UpperHex for HexPrimitive<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_hex(f, Case::Upper) }
}
+/// An error type for errors that can occur during parsing of a `Decodable` type from hex.
+pub(crate) enum ParsePrimitiveError<T: Decodable> {
+ /// Tried to decode an odd length string
+ OddLengthString(hex_unstable::OddLengthStringError),
+ /// Encountered an invalid hex character
+ InvalidChar(hex_unstable::InvalidCharError),
+ /// A decode error from `consensus_encoding`
+ Decode(<T::Decoder as Decoder>::Error),
+}
+
+impl<T: Decodable> fmt::Debug for ParsePrimitiveError<T> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::OddLengthString(ref e) => write_err!(f, "odd length string"; e),
+ Self::InvalidChar(ref e) => write_err!(f, "invalid character"; e),
+ Self::Decode(_) => write!(f, "failure decoding hex string into {}", core::any::type_name::<T>()),
+ }
+ }
+}
+
+impl<T: Decodable> fmt::Display for ParsePrimitiveError<T> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self, f) }
+}
+
+impl<T: Decodable> From<hex_unstable::OddLengthStringError> for ParsePrimitiveError<T> {
+ fn from(err: hex_unstable::OddLengthStringError) -> Self { Self::OddLengthString(err) }
+}
+
+impl<T: Decodable> From<hex_unstable::InvalidCharError> for ParsePrimitiveError<T> {
+ fn from(err: hex_unstable::InvalidCharError) -> Self { Self::InvalidChar(err) }
+}
+
+impl<T: Decodable> From<core::convert::Infallible> for ParsePrimitiveError<T> {
+ fn from(never: core::convert::Infallible) -> Self { match never {} }
+}
+
+#[cfg(feature = "std")]
+impl<T: Decodable> std::error::Error for ParsePrimitiveError<T> {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::OddLengthString(ref e) => Some(e),
+ Self::InvalidChar(ref e) => Some(e),
+ Self::Decode(_) => None,
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
#[cfg(feature = "alloc")]
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.