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 Feb 24, 2022
1 parent e0767d3 commit 670da82
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/key.rs
Expand Up @@ -19,6 +19,7 @@
#[cfg(any(test, feature = "rand"))] use rand::Rng;

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

use super::{from_hex, Secp256k1};
Expand Down Expand Up @@ -1236,6 +1237,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 670da82

Please sign in to comment.