Skip to content

Commit

Permalink
Implemented TryFrom<{u8, i32}> for Parity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kixunil committed Jun 10, 2022
1 parent a9dec5a commit 31bb35a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/key.rs
Expand Up @@ -17,6 +17,7 @@
//!

use core::{fmt, ptr, str};
use core::convert::TryFrom;
use core::ops::BitXor;
use core::convert::TryFrom;

Expand Down Expand Up @@ -1277,6 +1278,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

0 comments on commit 31bb35a

Please sign in to comment.