From cabb8f9e6fc11ec42d8ce8ebfc64d62c8bf0720a Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 24 Feb 2022 16:27:38 +0100 Subject: [PATCH 1/2] Implemented `TryFrom<{u8, i32}>` for `Parity` --- src/key.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/key.rs b/src/key.rs index 4f715d8..8d883aa 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1277,6 +1277,24 @@ impl Parity { } } +/// `Even` for `0`, `Odd` for `1`, error for anything else +impl TryFrom for Parity { + type Error = InvalidParityValue; + + fn try_from(parity: i32) -> Result { + Self::from_i32(parity) + } +} + +/// `Even` for `0`, `Odd` for `1`, error for anything else +impl TryFrom for Parity { + type Error = InvalidParityValue; + + fn try_from(parity: u8) -> Result { + Self::from_u8(parity) + } +} + /// The conversion returns `0` for even parity and `1` for odd. impl From for i32 { fn from(parity: Parity) -> i32 { From df081bede00a61f410f2c2f5aff8ab0e134003f0 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Mon, 28 Feb 2022 21:13:54 +0100 Subject: [PATCH 2/2] Changed impl `Error::cause()` to `Error::source()` This implements `source()` method instead of `cause()` allowing downcasting. --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f1cc959..050b674 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -377,8 +377,7 @@ impl fmt::Display for Error { #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] impl std::error::Error for Error { - #[allow(deprecated)] - fn cause(&self) -> Option<&dyn std::error::Error> { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { Error::IncorrectSignature => None, Error::InvalidMessage => None,