Repository: alex/rust-asn1 (language: rust)

Issue:
WriteError does not implement std::error::Error
All error types should implement this trait.


Discussion / hints:
Yes this is a good idea. are you interested in submitting a patch for this?

Fix patch:
diff --git a/src/writer.rs b/src/writer.rs
index 6554dc9..3f9e6f5 100644
--- a/src/writer.rs
+++ b/src/writer.rs
@@ -1,7 +1,7 @@
 use crate::types::{Asn1Writable, SimpleAsn1Writable};
 use crate::Tag;
-use alloc::vec;
 use alloc::vec::Vec;
+use alloc::{fmt, vec};
 
 /// `WriteError` are returned when there is an error writing the ASN.1 data.
 ///
@@ -14,6 +14,17 @@ pub enum WriteError {
     AllocationError,
 }
 
+impl fmt::Display for WriteError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match self {
+            WriteError::AllocationError => write!(f, "allocation error"),
+        }
+    }
+}
+
+#[cfg(feature = "std")]
+impl std::error::Error for WriteError {}
+
 pub type WriteResult<T = ()> = Result<T, WriteError>;
 
 pub struct WriteBuf(Vec<u8>);
@@ -719,4 +730,10 @@ mod tests {
             (Box::new(0), b"\x02\x01\x00"),
         ]);
     }
+
+    #[test]
+    fn test_write_error_display() {
+        use alloc::string::ToString;
+        assert_eq!(&WriteError::AllocationError.to_string(), "allocation error");
+    }
 }


Test patch: