Skip to content

Commit 73ad30d

Browse files
committed
Merge #409: After MSRV bump: Implemented TryFrom<{u8, i32}> for Parity
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
2 parents 6577fba + df081be commit 73ad30d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/key.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,24 @@ impl Parity {
12771277
}
12781278
}
12791279

1280+
/// `Even` for `0`, `Odd` for `1`, error for anything else
1281+
impl TryFrom<i32> for Parity {
1282+
type Error = InvalidParityValue;
1283+
1284+
fn try_from(parity: i32) -> Result<Self, Self::Error> {
1285+
Self::from_i32(parity)
1286+
}
1287+
}
1288+
1289+
/// `Even` for `0`, `Odd` for `1`, error for anything else
1290+
impl TryFrom<u8> for Parity {
1291+
type Error = InvalidParityValue;
1292+
1293+
fn try_from(parity: u8) -> Result<Self, Self::Error> {
1294+
Self::from_u8(parity)
1295+
}
1296+
}
1297+
12801298
/// The conversion returns `0` for even parity and `1` for odd.
12811299
impl From<Parity> for i32 {
12821300
fn from(parity: Parity) -> i32 {

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ impl fmt::Display for Error {
372372
#[cfg(feature = "std")]
373373
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
374374
impl std::error::Error for Error {
375-
#[allow(deprecated)]
376-
fn cause(&self) -> Option<&dyn std::error::Error> {
375+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
377376
match self {
378377
Error::IncorrectSignature => None,
379378
Error::InvalidMessage => None,

0 commit comments

Comments
 (0)