Struct currencies::amount::Amount

source ·
pub struct Amount<C = USD, Safety = Unchecked>(/* private fields */)
where
    C: Currency,
    Safety: Safety;
Expand description

Generically represents an amount of a specified Currency.

Setting Self::Safety to Unchecked will allow for full use of all supported math operators, but allows for things like overflowing, division by zero, that can lead to panics during runtime.

Setting Self::Safety to Checked replaces basic arithmetic operators with their checked counterparts that can never panic but typically return an Option or Result that must be used. This should make usages of this Amount 100% safe to use in situations where panicking is dangerous.

Implementations§

source§

impl<C, Safety> Amount<C, Safety>
where C: Currency, Safety: Safety,

source

pub fn raw_backing(&self) -> <C as Currency>::Backing

Allows direct access to the raw Backing value used to internally represent this Amount.

source

pub fn raw_backing_mut(&mut self) -> &mut <C as Currency>::Backing

Allows direct mutable access to the raw Backing value used to internally represent this Amount.

This method should be used with care as no checks are performed when directly manipulating the internal Backing.

source§

impl<C, Safety> Amount<C, Safety>
where C: Currency, Safety: Safety,

source

pub const fn from_raw(amount: <C as Currency>::Backing) -> Amount<C, Safety>

Constructs an Amount from a compatible raw Backing value.

Trait Implementations§

source§

impl<C> Add for Amount<C>
where C: Currency,

§

type Output = Amount<C>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Amount<C>) -> <Amount<C> as Add>::Output

Performs the + operation. Read more
source§

impl<C> Add for Amount<C, Checked>
where C: Currency,

§

type Output = Option<Amount<C, Checked>>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Amount<C, Checked>) -> <Amount<C, Checked> as Add>::Output

Performs the + operation. Read more
source§

impl<C> AddAssign for Amount<C>
where C: Currency,

source§

fn add_assign(&mut self, rhs: Amount<C>)

Performs the += operation. Read more
source§

impl<C, Safety> Clone for Amount<C, Safety>
where C: Clone + Currency, Safety: Clone + Safety, <C as Currency>::Backing: Clone,

source§

fn clone(&self) -> Amount<C, Safety>

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<C, Safety> Debug for Amount<C, Safety>
where C: Currency, Safety: Safety,

source§

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

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

impl<'de, C, Safety> Deserialize<'de> for Amount<C, Safety>
where C: Currency, Safety: Safety, Amount<C, Safety>: FromStr<Err = Error>,

source§

fn deserialize<D>( deserializer: D, ) -> Result<Amount<C, Safety>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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

impl<C, Safety> Display for Amount<C, Safety>
where C: Currency, Safety: Safety,

source§

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

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

impl<C> Div for Amount<C>
where C: Currency,

§

type Output = <C as Currency>::Backing

The resulting type after applying the / operator.
source§

fn div(self, rhs: Amount<C>) -> <Amount<C> as Div>::Output

Performs the / operation. Read more
source§

impl<C> Div for Amount<C, Checked>
where C: Currency,

§

type Output = Option<<C as Currency>::Backing>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Amount<C, Checked>) -> <Amount<C, Checked> as Div>::Output

Performs the / operation. Read more
source§

impl<C> From<Amount<C>> for Amount<C, Checked>
where C: Currency,

source§

fn from(amount: Amount<C>) -> Amount<C, Checked>

Converts to this type from the input type.
source§

impl<C> From<Amount<C, Checked>> for Amount<C>
where C: Currency,

source§

fn from(amount: Amount<C, Checked>) -> Amount<C>

Converts to this type from the input type.
source§

impl<C, Safety> FromStr for Amount<C, Safety>
where C: Currency, Safety: Safety,

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str( s: &str, ) -> Result<Amount<C, Safety>, <Amount<C, Safety> as FromStr>::Err>

Parses a string s to return a value of this type. Read more
source§

impl<C, Safety> Hash for Amount<C, Safety>
where C: Hash + Currency, Safety: Hash + Safety, <C as Currency>::Backing: Hash,

source§

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

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<C> Mul<i32> for Amount<C>

§

type Output = Amount<C>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: i32) -> <Amount<C> as Mul<i32>>::Output

Performs the * operation. Read more
source§

impl<C> Mul<u128> for Amount<C>

§

type Output = Amount<C>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: u128) -> <Amount<C> as Mul<u128>>::Output

Performs the * operation. Read more
source§

impl<C> Mul<u16> for Amount<C>

§

type Output = Amount<C>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: u16) -> <Amount<C> as Mul<u16>>::Output

Performs the * operation. Read more
source§

impl<C> Mul<u32> for Amount<C>

§

type Output = Amount<C>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: u32) -> <Amount<C> as Mul<u32>>::Output

Performs the * operation. Read more
source§

impl<C> Mul<u64> for Amount<C>

§

type Output = Amount<C>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: u64) -> <Amount<C> as Mul<u64>>::Output

Performs the * operation. Read more
source§

impl<C> Mul<u8> for Amount<C>

§

type Output = Amount<C>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: u8) -> <Amount<C> as Mul<u8>>::Output

Performs the * operation. Read more
source§

impl<C> Mul<usize> for Amount<C>

§

type Output = Amount<C>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: usize) -> <Amount<C> as Mul<usize>>::Output

Performs the * operation. Read more
source§

impl<C> Mul for Amount<C>
where C: Currency,

§

type Output = Amount<C>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Amount<C>) -> <Amount<C> as Mul>::Output

Performs the * operation. Read more
source§

impl<C> Mul for Amount<C, Checked>
where C: Currency,

§

type Output = Option<Amount<C, Checked>>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Amount<C, Checked>) -> <Amount<C, Checked> as Mul>::Output

Performs the * operation. Read more
source§

impl<C> MulAssign for Amount<C>
where C: Currency,

source§

fn mul_assign(&mut self, rhs: Amount<C>)

Performs the *= operation. Read more
source§

impl<C> One for Amount<C>
where C: Currency,

source§

fn one() -> Amount<C>

Returns the multiplicative identity element of Self, 1. Read more
source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
source§

impl<C, Safety> Ord for Amount<C, Safety>
where C: Ord + Currency, Safety: Ord + Safety, <C as Currency>::Backing: Ord,

source§

fn cmp(&self, other: &Amount<C, Safety>) -> Ordering

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

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

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

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

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

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

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

impl<C, Safety> PartialEq for Amount<C, Safety>
where C: PartialEq + Currency, Safety: PartialEq + Safety, <C as Currency>::Backing: PartialEq,

source§

fn eq(&self, other: &Amount<C, Safety>) -> 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<C, Safety> PartialOrd for Amount<C, Safety>

source§

fn partial_cmp(&self, other: &Amount<C, Safety>) -> 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<C, Safety> Rem for Amount<C, Safety>
where C: Currency, Safety: Safety,

§

type Output = Amount<C, Safety>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Amount<C, Safety>) -> <Amount<C, Safety> as Rem>::Output

Performs the % operation. Read more
source§

impl<C, Safety> Serialize for Amount<C, Safety>
where C: Currency, Safety: Safety,

source§

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
source§

impl<C> Sub for Amount<C>
where C: Currency,

§

type Output = Amount<C>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Amount<C>) -> <Amount<C> as Sub>::Output

Performs the - operation. Read more
source§

impl<C> Sub for Amount<C, Checked>
where C: Currency,

§

type Output = Option<Amount<C, Checked>>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Amount<C, Checked>) -> <Amount<C, Checked> as Sub>::Output

Performs the - operation. Read more
source§

impl<C> SubAssign for Amount<C>
where C: Currency,

source§

fn sub_assign(&mut self, rhs: Amount<C>)

Performs the -= operation. Read more
source§

impl<C> Zero for Amount<C>
where C: Currency,

source§

fn zero() -> Amount<C>

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<C, Safety> Copy for Amount<C, Safety>
where C: Copy + Currency, Safety: Copy + Safety, <C as Currency>::Backing: Copy,

source§

impl<C, Safety> Eq for Amount<C, Safety>
where C: Eq + Currency, Safety: Eq + Safety, <C as Currency>::Backing: Eq,

source§

impl<C, Safety> StructuralPartialEq for Amount<C, Safety>
where C: Currency, Safety: Safety,

Auto Trait Implementations§

§

impl<C, Safety> Freeze for Amount<C, Safety>
where <C as Currency>::Backing: Freeze,

§

impl<C, Safety> RefUnwindSafe for Amount<C, Safety>

§

impl<C, Safety> Send for Amount<C, Safety>
where <C as Currency>::Backing: Send, C: Send, Safety: Send,

§

impl<C, Safety> Sync for Amount<C, Safety>
where <C as Currency>::Backing: Sync, C: Sync, Safety: Sync,

§

impl<C, Safety> Unpin for Amount<C, Safety>
where <C as Currency>::Backing: Unpin, C: Unpin, Safety: Unpin,

§

impl<C, Safety> UnwindSafe for Amount<C, Safety>
where <C as Currency>::Backing: UnwindSafe, C: UnwindSafe, Safety: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> ToOwned for T
where 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 T
where 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 T
where 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 T
where 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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

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

source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,