Merge rust-bitcoin/rust-secp256k1#409: After MSRV bump: Implemented `TryFrom<{u8, i32}>` for `Parity`

df081bede0 Changed impl `Error::cause()` to `Error::source()` (Martin Habovstiak)
cabb8f9e6f Implemented `TryFrom<{u8, i32}>` for `Parity` (Martin Habovstiak)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK df081bede0
  apoelstra:
    ACK df081bede0

Tree-SHA512: 5587a9684a4bfc1f659548a3787ff3602c56b2d6db72e89783529b85b670b681bce7e99683c751a03697c8faa1c2aa2f314c2c9b28e16e4c53fd07b01e949af2
This commit is contained in:
Andrew Poelstra 2022-06-15 15:08:29 +00:00
commit 73ad30dda1
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 19 additions and 2 deletions

View File

@ -1277,6 +1277,24 @@ impl Parity {
}
}
/// `Even` for `0`, `Odd` for `1`, error for anything else
impl TryFrom<i32> for Parity {
type Error = InvalidParityValue;
fn try_from(parity: i32) -> Result<Self, Self::Error> {
Self::from_i32(parity)
}
}
/// `Even` for `0`, `Odd` for `1`, error for anything else
impl TryFrom<u8> for Parity {
type Error = InvalidParityValue;
fn try_from(parity: u8) -> Result<Self, Self::Error> {
Self::from_u8(parity)
}
}
/// The conversion returns `0` for even parity and `1` for odd.
impl From<Parity> for i32 {
fn from(parity: Parity) -> i32 {

View File

@ -372,8 +372,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,