pub struct EtherAmount(pub u128);Expand description
A wrapper for ether amounts.
§Examples
In non-const context, the most idiomatic way to produce a size is to multiply EtherUnit by u128:
let size = 100 * EtherUnit::Gwei;
assert_eq!(size, EtherAmount(100_000_000_000));In const context, Self::new() may be used instead:
const AMOUNT: EtherAmount = EtherAmount::new(100, EtherUnit::Gwei);
assert_eq!(AMOUNT, EtherAmount(100_000_000_000));§As config param
EtherAmount can be parsed from a string with a unit suffix. See also WithUnit.
let amount: EtherAmount = "123 gwei".parse()?;
assert_eq!(amount, 123 * EtherUnit::Gwei);
// Decimal values are supported. The value conversion is lossless.
let amount: EtherAmount = "0.0013 ether".parse()?;
assert_eq!(amount, 1_300_000 * EtherUnit::Gwei);
// Scientific / exponential notation is supported as well.
let amount: EtherAmount = "2.5e12 wei".parse()?;
assert_eq!(amount, EtherAmount(2_500_000_000_000));Tuple Fields§
§0: u128Implementations§
Source§impl EtherAmount
impl EtherAmount
Sourcepub const fn checked(val: u128, unit: EtherUnit) -> Option<Self>
pub const fn checked(val: u128, unit: EtherUnit) -> Option<Self>
Creates a value with the specified unit of measurement checking for overflow.
Sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Adds two byte sizes.
Sourcepub const fn checked_mul(self, factor: u128) -> Option<Self>
pub const fn checked_mul(self, factor: u128) -> Option<Self>
Multiplies this size by the given factor.
Trait Implementations§
Source§impl Add for EtherAmount
Panics on overflow.
impl Add for EtherAmount
Panics on overflow.
Source§impl Clone for EtherAmount
impl Clone for EtherAmount
Source§fn clone(&self) -> EtherAmount
fn clone(&self) -> EtherAmount
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl CustomKnownOption for EtherAmount
impl CustomKnownOption for EtherAmount
Source§const OPT_DE: Self::OptDeserializer
const OPT_DE: Self::OptDeserializer
Deserializer instance.
Source§type OptDeserializer = Optional<WithUnit, true>
type OptDeserializer = Optional<WithUnit, true>
Type of the deserializer used for
Option<Self>.Source§impl Debug for EtherAmount
impl Debug for EtherAmount
Source§impl Default for EtherAmount
impl Default for EtherAmount
Source§fn default() -> EtherAmount
fn default() -> EtherAmount
Returns the “default value” for a type. Read more
Source§impl DeserializeParam<EtherAmount> for WithUnit
impl DeserializeParam<EtherAmount> for WithUnit
Source§const EXPECTING: BasicTypes = Self::EXPECTED_TYPES
const EXPECTING: BasicTypes = Self::EXPECTED_TYPES
Describes which parameter this deserializer is expecting.
Source§fn describe(&self, description: &mut TypeDescription)
fn describe(&self, description: &mut TypeDescription)
Additional info about the deserialized type, e.g., extended description.
Source§fn deserialize_param(
&self,
ctx: DeserializeContext<'_>,
param: &'static ParamMetadata,
) -> Result<EtherAmount, ErrorWithOrigin>
fn deserialize_param( &self, ctx: DeserializeContext<'_>, param: &'static ParamMetadata, ) -> Result<EtherAmount, ErrorWithOrigin>
Performs deserialization given the context and param metadata. Read more
Source§fn serialize_param(&self, param: &EtherAmount) -> Value
fn serialize_param(&self, param: &EtherAmount) -> Value
Serializes the provided parameter to the JSON model. Read more
Source§impl Display for EtherAmount
impl Display for EtherAmount
Source§impl From<EtherUnit> for EtherAmount
impl From<EtherUnit> for EtherAmount
Source§impl From<u128> for EtherAmount
impl From<u128> for EtherAmount
Source§impl FromStr for EtherAmount
impl FromStr for EtherAmount
Source§impl Hash for EtherAmount
impl Hash for EtherAmount
Source§impl Mul<u128> for EtherAmount
Panics on overflow.
impl Mul<u128> for EtherAmount
Panics on overflow.
Source§impl Ord for EtherAmount
impl Ord for EtherAmount
Source§fn cmp(&self, other: &EtherAmount) -> Ordering
fn cmp(&self, other: &EtherAmount) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for EtherAmount
impl PartialEq for EtherAmount
Source§impl PartialOrd for EtherAmount
impl PartialOrd for EtherAmount
Source§impl WellKnown for EtherAmount
impl WellKnown for EtherAmount
Source§const DE: Self::Deserializer = WithUnit
const DE: Self::Deserializer = WithUnit
Deserializer instance.
Source§type Deserializer = WithUnit
type Deserializer = WithUnit
Type of the deserializer used for this type.
impl Copy for EtherAmount
impl Eq for EtherAmount
impl StructuralPartialEq for EtherAmount
Auto Trait Implementations§
impl Freeze for EtherAmount
impl RefUnwindSafe for EtherAmount
impl Send for EtherAmount
impl Sync for EtherAmount
impl Unpin for EtherAmount
impl UnwindSafe for EtherAmount
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.