pub struct TokenAmount { /* private fields */ }
Expand description

A quantity of native tokens. A token amount is an integer, but has a human interpretation as a value with 18 decimal places. This is a new-type in order to prevent accidental conversion from other BigInts. From/Into BigInt is missing by design.

Implementations§

source§

impl TokenAmount

source

pub const DECIMALS: usize = 18usize

The logical number of decimal places of a token unit.

source

pub const PRECISION: u64 = 1_000_000_000_000_000_000u64

The logical precision of a token unit.

source

pub fn from_atto(atto: impl Into<BigInt>) -> Self

Creates a token amount from a quantity of indivisible units (10^-18 whole units).

source

pub fn from_nano(nano: impl Into<BigInt>) -> Self

Creates a token amount from nanoFIL.

source

pub fn from_whole(tokens: impl Into<BigInt>) -> Self

Creates a token amount from a quantity of whole units (10^18 indivisible units).

source

pub fn atto(&self) -> &BigInt

Returns the quantity of indivisible units.

source

pub fn is_zero(&self) -> bool

source

pub fn is_positive(&self) -> bool

source

pub fn is_negative(&self) -> bool

source§

impl TokenAmount

source

pub fn div_rem(&self, other: impl Into<BigInt>) -> (TokenAmount, TokenAmount)

source

pub fn div_ceil(&self, other: impl Into<BigInt>) -> TokenAmount

source

pub fn div_floor(&self, other: impl Into<BigInt>) -> TokenAmount

Trait Implementations§

source§

impl<'a, 'b> Add<&'b TokenAmount> for &'a TokenAmount

§

type Output = TokenAmount

The resulting type after applying the + operator.
source§

fn add(self, other: &'b TokenAmount) -> TokenAmount

Performs the + operation. Read more
source§

impl<'b> Add<&'b TokenAmount> for TokenAmount

§

type Output = TokenAmount

The resulting type after applying the + operator.
source§

fn add(self, other: &'b TokenAmount) -> TokenAmount

Performs the + operation. Read more
source§

impl<'a> Add<TokenAmount> for &'a TokenAmount

§

type Output = TokenAmount

The resulting type after applying the + operator.
source§

fn add(self, other: TokenAmount) -> TokenAmount

Performs the + operation. Read more
source§

impl Add<TokenAmount> for TokenAmount

§

type Output = TokenAmount

The resulting type after applying the + operator.
source§

fn add(self, other: TokenAmount) -> TokenAmount

Performs the + operation. Read more
source§

impl<'a> AddAssign<&'a TokenAmount> for TokenAmount

source§

fn add_assign(&mut self, other: &TokenAmount)

Performs the += operation. Read more
source§

impl AddAssign<TokenAmount> for TokenAmount

source§

fn add_assign(&mut self, other: TokenAmount)

Performs the += operation. Read more
source§

impl Clone for TokenAmount

source§

fn clone(&self) -> TokenAmount

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TokenAmount

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for TokenAmount

source§

fn default() -> TokenAmount

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for TokenAmount

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for TokenAmount

Displays a token amount as a decimal in human units. To avoid any confusion over whether the value is in human-scale or indivisible units, the display always includes a decimal point.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<TokenAmount> for TokenAmount

source§

fn from(v: TokenAmount) -> Self

Converts to this type from the input type.
source§

impl Hash for TokenAmount

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a BigInt

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a i128

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a i16

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a i32

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a i64

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a i8

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a u128

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a u16

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a u32

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a u64

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, 'b> Mul<&'b TokenAmount> for &'a u8

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for BigInt

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for i128

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for i16

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for i32

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for i64

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for i8

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for u128

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for u16

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for u32

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for u64

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'b> Mul<&'b TokenAmount> for u8

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a, T> Mul<T> for &'a TokenAmountwhere &'a BigInt: Mul<T, Output = BigInt>,

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl<T> Mul<T> for TokenAmountwhere BigInt: Mul<T, Output = BigInt>,

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a BigInt

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a i128

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a i16

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a i32

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a i64

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a i8

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a u128

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a u16

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a u32

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a u64

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<'a> Mul<TokenAmount> for &'a u8

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for BigInt

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for i128

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for i16

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for i32

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for i64

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for i8

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for u128

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for u16

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for u32

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for u64

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl Mul<TokenAmount> for u8

§

type Output = TokenAmount

The resulting type after applying the * operator.
source§

fn mul(self, other: TokenAmount) -> TokenAmount

Performs the * operation. Read more
source§

impl<T> MulAssign<T> for TokenAmountwhere BigInt: MulAssign<T>,

source§

fn mul_assign(&mut self, other: T)

Performs the *= operation. Read more
source§

impl<'a> Neg for &'a TokenAmount

§

type Output = TokenAmount

The resulting type after applying the - operator.
source§

fn neg(self) -> TokenAmount

Performs the unary - operation. Read more
source§

impl Neg for TokenAmount

§

type Output = TokenAmount

The resulting type after applying the - operator.
source§

fn neg(self) -> TokenAmount

Performs the unary - operation. Read more
source§

impl Ord for TokenAmount

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<TokenAmount> for TokenAmount

source§

fn eq(&self, other: &TokenAmount) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<TokenAmount> for TokenAmount

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for TokenAmount

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'a, 'b> Sub<&'b TokenAmount> for &'a TokenAmount

§

type Output = TokenAmount

The resulting type after applying the - operator.
source§

fn sub(self, other: &'b TokenAmount) -> TokenAmount

Performs the - operation. Read more
source§

impl<'b> Sub<&'b TokenAmount> for TokenAmount

§

type Output = TokenAmount

The resulting type after applying the - operator.
source§

fn sub(self, other: &'b TokenAmount) -> TokenAmount

Performs the - operation. Read more
source§

impl<'a> Sub<TokenAmount> for &'a TokenAmount

§

type Output = TokenAmount

The resulting type after applying the - operator.
source§

fn sub(self, other: TokenAmount) -> TokenAmount

Performs the - operation. Read more
source§

impl Sub<TokenAmount> for TokenAmount

§

type Output = TokenAmount

The resulting type after applying the - operator.
source§

fn sub(self, other: TokenAmount) -> TokenAmount

Performs the - operation. Read more
source§

impl<'a> SubAssign<&'a TokenAmount> for TokenAmount

source§

fn sub_assign(&mut self, other: &TokenAmount)

Performs the -= operation. Read more
source§

impl SubAssign<TokenAmount> for TokenAmount

source§

fn sub_assign(&mut self, other: TokenAmount)

Performs the -= operation. Read more
source§

impl<'a> Sum<&'a TokenAmount> for TokenAmount

source§

fn sum<I: Iterator<Item = &'a TokenAmount>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl Sum<TokenAmount> for TokenAmount

source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Method which takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl<'a> TryFrom<&'a TokenAmount> for TokenAmount

§

type Error = TryFromBigIntError<()>

The type returned in the event of a conversion error.
source§

fn try_from(v: &'a TokenAmount) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<TokenAmount> for TokenAmount

§

type Error = TryFromBigIntError<()>

The type returned in the event of a conversion error.
source§

fn try_from(v: TokenAmount) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Zero for TokenAmount

source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

impl Eq for TokenAmount

source§

impl StructuralEq for TokenAmount

source§

impl StructuralPartialEq for TokenAmount

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,