pub struct Unit(/* private fields */);
Expand description
Ethereum unit. Always less than 77
.
Implementations§
Source§impl Unit
impl Unit
Sourcepub const fn new(units: u8) -> Option<Self>
pub const fn new(units: u8) -> Option<Self>
Creates a new Unit
instance, checking for overflow.
Sourcepub const unsafe fn new_unchecked(x: u8) -> Self
pub const unsafe fn new_unchecked(x: u8) -> Self
Sourcepub fn wei(self) -> U256
pub fn wei(self) -> U256
Returns 10^self
, which is the number of Wei in this unit.
§Examples
use alloy_primitives::{utils::Unit, U256};
assert_eq!(U256::from(1u128), Unit::WEI.wei());
assert_eq!(U256::from(1_000u128), Unit::KWEI.wei());
assert_eq!(U256::from(1_000_000u128), Unit::MWEI.wei());
assert_eq!(U256::from(1_000_000_000u128), Unit::GWEI.wei());
assert_eq!(U256::from(1_000_000_000_000u128), Unit::TWEI.wei());
assert_eq!(U256::from(1_000_000_000_000_000u128), Unit::PWEI.wei());
assert_eq!(U256::from(1_000_000_000_000_000_000u128), Unit::ETHER.wei());
Trait Implementations§
Source§impl Ord for Unit
impl Ord for Unit
Source§impl PartialOrd for Unit
impl PartialOrd for Unit
impl Copy for Unit
impl Eq for Unit
impl StructuralPartialEq for Unit
Auto Trait Implementations§
impl Freeze for Unit
impl RefUnwindSafe for Unit
impl Send for Unit
impl Sync for Unit
impl Unpin for Unit
impl UnwindSafe for Unit
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,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.