Skip to content

Commit

Permalink
More conversion traits
Browse files Browse the repository at this point in the history
  • Loading branch information
douweschulte committed Dec 6, 2023
1 parent f0565ab commit 13cf456
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/shared/aminoacid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ impl AminoAcid {
}
}

impl std::str::FromStr for AminoAcid {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(s)
}
}

impl TryFrom<&str> for AminoAcid {
type Error = ();
fn try_from(value: &str) -> Result<Self, Self::Error> {
Expand All @@ -93,9 +100,9 @@ impl TryFrom<char> for AminoAcid {
}
}

impl TryFrom<u8> for AminoAcid {
impl TryFrom<&u8> for AminoAcid {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
fn try_from(value: &u8) -> Result<Self, Self::Error> {
match value {
b'A' | b'a' => Ok(Self::Alanine),
b'B' | b'b' => Ok(Self::AmbiguousAsparagine),
Expand Down Expand Up @@ -127,3 +134,10 @@ impl TryFrom<u8> for AminoAcid {
}
}
}

impl TryFrom<u8> for AminoAcid {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(&value)
}
}

0 comments on commit 13cf456

Please sign in to comment.