pub struct Currency {
pub symbol: Option<char>,
pub value: i64,
}
Expand description
Represents currency through an optional symbol and amount of coin.
Each 100 coins results in a banknote. (100 is formatted as 1.00)
The currency will be formatted as such: Currency(Some('$'), 432)
==> โ$4.32โ
Fieldsยง
ยงsymbol: Option<char>
Currency symbol
pick any of โฌ
, ยฃ
, $
, ยฅ
etcโฆ
value: i64
value in the smallest possible unit
Implementationsยง
sourceยงimpl Currency
impl Currency
sourcepub fn from_value(value: i64) -> Currency
pub fn from_value(value: i64) -> Currency
Initialize from i64
sourcepub fn postfix(&self) -> Postfix<'_>
pub fn postfix(&self) -> Postfix<'_>
Returns an object that implements Display
for different methods of printing currency.
sourcepub fn prefix(&self) -> Prefix<'_>
pub fn prefix(&self) -> Prefix<'_>
Returns an object that implements Display
for different methods of printing currency.
sourcepub fn as_float(&self) -> f64
pub fn as_float(&self) -> f64
Returns the value as float
Warning, do not use this for calculation, this is for displaying only!
Methods from Deref<Target = i64>ยง
Trait Implementationsยง
sourceยงimpl Add<Currency> for Currency
impl Add<Currency> for Currency
Overloads the โ+โ operator for Currency objects.
Panics
Panics if the two addends are different types of currency, as denoted by the Currencyโs symbol.
sourceยงimpl Div<i64> for Currency
impl Div<i64> for Currency
Overloads the โ/โ operator for Currency objects.
Allows a Currency to be divided by an i64.
sourceยงimpl Mul<Currency> for i64
impl Mul<Currency> for i64
Overloads the โ*โ operator for i64.
Allows an i64 to be multiplied by a Currency. Completes the commutative property for i64 multiplied by Currency.
sourceยงimpl Mul<f64> for Currency
impl Mul<f64> for Currency
Multiplies with float, probably not a good idea, help appreciated.
sourceยงimpl Mul<i64> for Currency
impl Mul<i64> for Currency
Overloads the โ*โ operator for Currency objects.
Allows a Currency to be multiplied by an i64.
sourceยงimpl PartialEq<Currency> for Currency
impl PartialEq<Currency> for Currency
sourceยงimpl PartialOrd<Currency> for Currency
impl PartialOrd<Currency> for Currency
1.0.0 ยท sourceยงfn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceยงimpl Serialize for Currency
impl Serialize for Currency
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,
sourceยงimpl Sub<Currency> for Currency
impl Sub<Currency> for Currency
Overloads the โ-โ operator for Currency objects.
Panics
Panics if the minuend and subtrahend are two different types of currency, as denoted by the Currencyโs symbol.