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: i64value 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.
Examples found in repository?
11fn print_items(items: &[BillItem<Product<'_>>]) {
12 //println!("{:?}", items);
13 for item in items {
14 println!(
15 " * {:3}x {:15} {:6} {:6}",
16 item.amount,
17 item.product.name,
18 item.product.price.postfix(),
19 item.gross().postfix()
20 );
21 }
22}
23
24fn print(title: &str, bill: &Bill<Product<'_>>) {
25 println!("{}:", title);
26 for (tax, items) in &bill.items_by_tax {
27 println!(" {}%", tax);
28 print_items(items);
29 }
30 println!("---------------------------------------");
31 println!(" {}", bill.gross_total().postfix());
32 println!(" + {} (tax)", bill.tax_total().postfix());
33 println!(" net {}", bill.net_total().postfix());
34 println!();
35}Sourcepub fn prefix(&self) -> Prefix<'_>
pub fn prefix(&self) -> Prefix<'_>
Returns an object that implements Display for different methods of printing currency.
Trait Implementationsยง
Sourceยงimpl Add for Currency
Overloads the โ+โ operator for Currency objects.
impl Add 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
Overloads the โ/โ operator for Currency objects.
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
Overloads the โ*โ operator 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
Multiplies with float, probably not a good idea, help appreciated.
impl Mul<f64> for Currency
Multiplies with float, probably not a good idea, help appreciated.
Sourceยงimpl Mul<i64> for Currency
Overloads the โ*โ operator for Currency objects.
impl Mul<i64> for Currency
Overloads the โ*โ operator for Currency objects.
Allows a Currency to be multiplied by an i64.
Sourceยงimpl PartialOrd for Currency
impl PartialOrd for Currency
Sourceยง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 for Currency
Overloads the โ-โ operator for Currency objects.
impl Sub 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.