Skip to content

Commit

Permalink
Impl TryFrom<&str> for Uint256 and Int256
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBorst committed Apr 29, 2024
1 parent b0f993e commit f646abe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/int256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ impl FromStr for Int256 {
}
}

impl TryFrom<&str> for Int256 {
type Error = String;

fn try_from(value: &str) -> Result<Self, Self::Error> {
value.parse()
}
}

impl TryFrom<Uint256> for Int256 {
type Error = ();

Expand Down
8 changes: 8 additions & 0 deletions src/uint256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ impl FromStr for Uint256 {
}
}

impl TryFrom<&str> for Uint256 {
type Error = String;

fn try_from(value: &str) -> Result<Self, Self::Error> {
value.parse()
}
}

impl fmt::Display for Uint256 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", &self.0.to_str_radix(10))
Expand Down

0 comments on commit f646abe

Please sign in to comment.