Struct Balance
pub struct Balance<C>(/* private fields */)
where
C: Currency;
Expand description
Represents a non-negative balance of some Currency
.
The value is internally always stored in wei
but always printed in human-readable format.
All arithmetic on this type is implicitly saturating at bounds given by [U256
].
Implementations§
§impl<C> Balance<C>where
C: Currency,
impl<C> Balance<C>where
C: Currency,
pub fn new_base<T>(value: T) -> Balance<C>where
T: Into<U256>,
pub fn new_base<T>(value: T) -> Balance<C>where
T: Into<U256>,
Creates new balance in base units, instead of wei
.
pub fn amount(&self) -> U256
pub fn amount(&self) -> U256
Gets the amount in wei
.
pub fn amount_in_base_units(&self) -> String
pub fn amount_in_base_units(&self) -> String
Returns the amount in base units (human-readable), not in wei
.
pub fn format_in_wei(&self) -> String
pub fn format_in_wei(&self) -> String
Prints the balance formated in wei
units.
Trait Implementations§
§impl<C, T> AddAssign<T> for Balance<C>
impl<C, T> AddAssign<T> for Balance<C>
§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
Performs the
+=
operation. Read more§impl<C> AddAssign for Balance<C>where
C: Currency,
impl<C> AddAssign for Balance<C>where
C: Currency,
§fn add_assign(&mut self, rhs: Balance<C>)
fn add_assign(&mut self, rhs: Balance<C>)
Performs the
+=
operation. Read more§impl<'de, C> Deserialize<'de> for Balance<C>where
C: Currency + Deserialize<'de>,
impl<'de, C> Deserialize<'de> for Balance<C>where
C: Currency + Deserialize<'de>,
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Balance<C>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Balance<C>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl<C> IntoEndian<32> for Balance<C>where
C: Currency,
impl<C> IntoEndian<32> for Balance<C>where
C: Currency,
§fn from_be_bytes<T>(bytes: T) -> Balance<C>
fn from_be_bytes<T>(bytes: T) -> Balance<C>
Create an instance from Big Endian bytes. Should panic if size is more than
N
.§fn from_le_bytes<T>(bytes: T) -> Balance<C>
fn from_le_bytes<T>(bytes: T) -> Balance<C>
Create an instance from Little Endian bytes. Should panic if size is more than
N
.§fn to_le_bytes(self) -> [u8; 32]
fn to_le_bytes(self) -> [u8; 32]
Convert instance to Little Endian bytes.
§fn to_be_bytes(self) -> [u8; 32]
fn to_be_bytes(self) -> [u8; 32]
Convert instance to Big Endian bytes.
§impl<C, T> MulAssign<T> for Balance<C>
impl<C, T> MulAssign<T> for Balance<C>
§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the
*=
operation. Read more§impl<C> MulAssign for Balance<C>where
C: Currency,
impl<C> MulAssign for Balance<C>where
C: Currency,
§fn mul_assign(&mut self, rhs: Balance<C>)
fn mul_assign(&mut self, rhs: Balance<C>)
Performs the
*=
operation. Read more§impl<C> Ord for Balance<C>
impl<C> Ord for Balance<C>
§impl<C> PartialOrd for Balance<C>where
C: PartialOrd + Currency,
impl<C> PartialOrd for Balance<C>where
C: PartialOrd + Currency,
§impl<C> Serialize for Balance<C>
impl<C> Serialize for Balance<C>
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
§impl<C, T> SubAssign<T> for Balance<C>
impl<C, T> SubAssign<T> for Balance<C>
§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
Performs the
-=
operation. Read more§impl<C> SubAssign for Balance<C>where
C: Currency,
impl<C> SubAssign for Balance<C>where
C: Currency,
§fn sub_assign(&mut self, rhs: Balance<C>)
fn sub_assign(&mut self, rhs: Balance<C>)
Performs the
-=
operation. Read moreimpl<C> Copy for Balance<C>
impl<C> Eq for Balance<C>
impl<C> StructuralPartialEq for Balance<C>where
C: Currency,
Auto Trait Implementations§
impl<C> Freeze for Balance<C>where
C: Freeze,
impl<C> RefUnwindSafe for Balance<C>where
C: RefUnwindSafe,
impl<C> Send for Balance<C>where
C: Send,
impl<C> Sync for Balance<C>where
C: Sync,
impl<C> Unpin for Balance<C>where
C: Unpin,
impl<C> UnwindSafe for Balance<C>where
C: UnwindSafe,
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
Compare self to
key
and return true
if they are equal.§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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.