Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After MSRV bump: Implemented TryFrom<{u8, i32}> for Parity #409

Merged
merged 2 commits into from Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -377,8 +377,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