Add default impls for standard error traits to ParsePrimitiveError
What changed, and why it matters
This commit adds standard Rust trait implementations (Clone, PartialEq, Eq, and Debug) to a custom error type called ParsePrimitiveError. It is a routine code-quality improvement that lets other error types automatically derive these same traits when they wrap ParsePrimitiveError. There is no security fix or behavior change here.
No security action needed. Treat as a normal library API improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch manually implements Clone, PartialEq, Eq, and Debug for ParsePrimitiveError
Changed components
primitives/src/hex_codec.rsInspect captured patch +34 / −0
diff --git a/primitives/src/hex_codec.rs b/primitives/src/hex_codec.rs
index 3c983ebf..787bfd4e 100644
--- a/primitives/src/hex_codec.rs
+++ b/primitives/src/hex_codec.rs
@@ -162,6 +162,8 @@ impl<T: Decodable> From<Infallible> for ParsePrimitiveError<T> {
fn from(never: Infallible) -> Self { match never {} }
}
+// Manual impls for Debug, Clone, PartialEq and Eq so that errors which wrap
+// `ParsePrimitiveError` can properly derive the defaults.
impl<T: Decodable> fmt::Debug for ParsePrimitiveError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
@@ -173,6 +175,38 @@ impl<T: Decodable> fmt::Debug for ParsePrimitiveError<T> {
}
}
+impl<T: Decodable> Clone for ParsePrimitiveError<T>
+where
+ <<T as Decodable>::Decoder as Decoder>::Error: Clone,
+{
+ fn clone(&self) -> Self {
+ match self {
+ Self::OddLengthString(ref e) => Self::OddLengthString(e.clone()),
+ Self::InvalidChar(ref e) => Self::InvalidChar(e.clone()),
+ Self::Decode(ref e) => Self::Decode(e.clone()),
+ }
+ }
+}
+
+impl<T: Decodable> PartialEq for ParsePrimitiveError<T>
+where
+ <<T as Decodable>::Decoder as Decoder>::Error: PartialEq,
+{
+ fn eq(&self, other: &Self) -> bool {
+ match (self, other) {
+ (Self::OddLengthString(ref e1), Self::OddLengthString(ref e2)) => e1 == e2,
+ (Self::InvalidChar(ref e1), Self::InvalidChar(ref e2)) => e1 == e2,
+ (Self::Decode(ref e1), Self::Decode(ref e2)) => e1 == e2,
+ _ => false,
+ }
+ }
+}
+
+impl<T: Decodable> Eq for ParsePrimitiveError<T> where
+ <<T as Decodable>::Decoder as Decoder>::Error: PartialEq
+{
+}
+
impl<T: Decodable> fmt::Display for ParsePrimitiveError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self, f) }
}
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.