Skip to content

Commit cabb8f9

Browse files
committed
Implemented TryFrom<{u8, i32}> for Parity
1 parent aab77b1 commit cabb8f9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
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 {

0 commit comments

Comments
 (0)