Skip to content

Commit

Permalink
feat(primitives): implement TryInto for ParseUnits (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jun 4, 2024
1 parent e1774c8 commit ec302cb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/primitives/src/utils/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ macro_rules! impl_from_integers {
impl_from_integers!(U256(u8, u16, u32, u64, u128, usize, U256));
impl_from_integers!(I256(i8, i16, i32, i64, i128, isize, I256));

macro_rules! impl_try_into_absolute {
($($t:ty),* $(,)?) => { $(
impl TryFrom<ParseUnits> for $t {
type Error = <$t as TryFrom<U256>>::Error;

fn try_from(value: ParseUnits) -> Result<Self, Self::Error> {
<$t>::try_from(value.get_absolute())
}
}
)* };
}

impl_try_into_absolute!(u64, u128);

impl ParseUnits {
/// Parses a decimal number and multiplies it with 10^units.
///
Expand Down

0 comments on commit ec302cb

Please sign in to comment.