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§
Trait Implementations§
source§impl<C> AddAssign for Amount<C>where
C: Currency,
impl<C> AddAssign for Amount<C>where
C: Currency,
source§fn add_assign(&mut self, rhs: Amount<C>)
fn add_assign(&mut self, rhs: Amount<C>)
Performs the
+=
operation. Read moresource§impl<'de, C, Safety> Deserialize<'de> for Amount<C, Safety>
impl<'de, C, Safety> Deserialize<'de> for Amount<C, Safety>
source§fn deserialize<D>(
deserializer: D,
) -> Result<Amount<C, Safety>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
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> MulAssign for Amount<C>where
C: Currency,
impl<C> MulAssign for Amount<C>where
C: Currency,
source§fn mul_assign(&mut self, rhs: Amount<C>)
fn mul_assign(&mut self, rhs: Amount<C>)
Performs the
*=
operation. Read moresource§impl<C, Safety> Ord for Amount<C, Safety>
impl<C, Safety> Ord for Amount<C, Safety>
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<C, Safety> PartialEq for Amount<C, Safety>
impl<C, Safety> PartialEq for Amount<C, Safety>
source§impl<C, Safety> PartialOrd for Amount<C, Safety>
impl<C, Safety> PartialOrd for Amount<C, Safety>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl<C, Safety> Serialize for Amount<C, Safety>
impl<C, Safety> Serialize for Amount<C, Safety>
source§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
source§impl<C> SubAssign for Amount<C>where
C: Currency,
impl<C> SubAssign for Amount<C>where
C: Currency,
source§fn sub_assign(&mut self, rhs: Amount<C>)
fn sub_assign(&mut self, rhs: Amount<C>)
Performs the
-=
operation. Read moreimpl<C, Safety> Copy for Amount<C, Safety>
impl<C, Safety> Eq for Amount<C, Safety>
impl<C, Safety> StructuralPartialEq for Amount<C, Safety>
Auto Trait Implementations§
impl<C, Safety> Freeze for Amount<C, Safety>
impl<C, Safety> RefUnwindSafe for Amount<C, Safety>
impl<C, Safety> Send for Amount<C, Safety>
impl<C, Safety> Sync for Amount<C, Safety>
impl<C, Safety> Unpin for Amount<C, Safety>
impl<C, Safety> UnwindSafe for Amount<C, Safety>
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