Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
impl TryFrom<U256> for Chain
Browse files Browse the repository at this point in the history
  • Loading branch information
recmo committed May 11, 2022
1 parent 0a03141 commit 341b275
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ethers-core/src/types/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ impl TryFrom<u64> for Chain {
}
}

impl TryFrom<U256> for Chain {
type Error = ParseChainError;

fn try_from(chain: U256) -> Result<Chain, Self::Error> {
if chain.bits() > 64 {
return Err(ParseChainError(chain.to_string()));
}
chain.as_u64().try_into()
}
}

impl FromStr for Chain {
type Err = ParseChainError;
fn from_str(chain: &str) -> Result<Self, Self::Err> {
Expand Down

0 comments on commit 341b275

Please sign in to comment.