diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs index 8069370c..f5f2f760 100644 --- a/ethers-core/src/types/chain.rs +++ b/ethers-core/src/types/chain.rs @@ -1,5 +1,4 @@ use super::{U128, U256, U512, U64}; -use num_enum::{TryFromPrimitive, TryFromPrimitiveError}; use serde::{Deserialize, Serialize, Serializer}; use std::{ convert::{TryFrom, TryInto}, @@ -8,6 +7,12 @@ use std::{ }; use strum::{AsRefStr, EnumString, EnumVariantNames}; +// compatibility re-export +#[doc(hidden)] +pub use num_enum::{TryFromPrimitive, TryFromPrimitiveError}; +#[doc(hidden)] +pub type ParseChainError = TryFromPrimitiveError; + // When adding a new chain: // 1. add new variant to the Chain enum; // 2. add extra information in the last `impl` block (explorer URLs, block time) when applicable; @@ -133,7 +138,7 @@ macro_rules! impl_try_from_numeric { ($($native:ty)+ ; $($primitive:ty)*) => { $( impl TryFrom<$native> for Chain { - type Error = TryFromPrimitiveError; + type Error = ParseChainError; fn try_from(value: $native) -> Result { (value as u64).try_into() @@ -143,13 +148,13 @@ macro_rules! impl_try_from_numeric { $( impl TryFrom<$primitive> for Chain { - type Error = TryFromPrimitiveError; + type Error = ParseChainError; fn try_from(value: $primitive) -> Result { if value.bits() > 64 { // `TryFromPrimitiveError` only has a `number` field which has the same type // as the `#[repr(_)]` attribute on the enum. - return Err(TryFromPrimitiveError { number: value.low_u64() }) + return Err(ParseChainError { number: value.low_u64() }) } value.low_u64().try_into() } @@ -167,7 +172,7 @@ impl From for u64 { impl_into_numeric!(u128 U64 U128 U256 U512); impl TryFrom for Chain { - type Error = TryFromPrimitiveError; + type Error = ParseChainError; fn try_from(value: U64) -> Result { value.low_u64().try_into()