errors: Implement std::error::Error for UnknownCryptoError
use core::fmt;
/// Opaque error.
-#[derive(PartialEq)]
+#[derive(Clone, Copy, PartialEq)]
pub struct UnknownCryptoError;
impl fmt::Display for UnknownCryptoError {
@@ -38,6 +38,13 @@ impl fmt::Debug for UnknownCryptoError {
}
}
+#[cfg(feature = "safe_api")]
+impl std::error::Error for UnknownCryptoError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ None
+ }
+}
+
#[cfg(feature = "safe_api")]
impl From<getrandom::Error> for UnknownCryptoError {
fn from(_: getrandom::Error) -> Self {
@@ -73,3 +80,10 @@ fn test_unknown_crypto_from_getrandom() {
let err = format!("{}", UnknownCryptoError::from(err_foreign));
assert_eq!(err, "UnknownCryptoError");
}
+
+#[test]
+#[cfg(feature = "safe_api")]
+fn test_source() {
+ use std::error::Error;
+ assert!(UnknownCryptoError.source().is_none());
+}
