Skip to content

Commit

Permalink
Merge #409: After MSRV bump: Implemented TryFrom<{u8, i32}> for `Pa…
Browse files Browse the repository at this point in the history
…rity`

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

Pull request description:

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

Tree-SHA512: 5587a9684a4bfc1f659548a3787ff3602c56b2d6db72e89783529b85b670b681bce7e99683c751a03697c8faa1c2aa2f314c2c9b28e16e4c53fd07b01e949af2
  • Loading branch information
apoelstra committed Jun 15, 2022
2 parents 6577fba + df081be commit 73ad30d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/key.rs
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Expand Up @@ -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,
Expand Down

0 comments on commit 73ad30d

Please sign in to comment.