Struct Currency Copy item path Source pub struct Currency {
pub symbol: Option <Symbol >,
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”
Currency symbol
pick any of €, £, $, ¥ etc…
value in the smallest possible unit
Creates a blank Currency as Currency(None, 0)
§ Examples
let mut c = Currency::new();Returns an object that implements Display for different methods of printing currency.
examples/initialization.rs (
line 6 )
3 fn display(my_money: Currency) {
4 println! ("I have {:?}!" , my_money);
5 println! ("I have {}!" , my_money.postfix ()); println! ("I have {}!" , my_money.prefix()); println! ()
9 }More examples Hide additional examples
3 fn main() {
4 let my_money = Currency {
5 symbol: Some ('€' ),
6 value: 4711 ,
7 };
8
9 println! ("I have {:?}!" , my_money);
10 println! ("I have {}!" , my_money.postfix ()); println! ("I have {}!" , my_money.prefix()); }Returns an object that implements Display for different methods of printing currency.
examples/initialization.rs (
line 7 )
3 fn display(my_money: Currency) {
4 println! ("I have {:?}!" , my_money);
5 println! ("I have {}!" , my_money.postfix()); println! ("I have {}!" , my_money.prefix ()); println! ()
9 }More examples Hide additional examples
3 fn main() {
4 let my_money = Currency {
5 symbol: Some ('€' ),
6 value: 4711 ,
7 };
8
9 println! ("I have {:?}!" , my_money);
10 println! ("I have {}!" , my_money.postfix()); println! ("I have {}!" , my_money.prefix ()); }Returns the value as float
§ Warning, do not use this for calculation, this is for displaying only!Source § Overloads the ‘+’ operator for Currency objects.
§ Panics
Panics if the two addends are different types of currency, as denoted by the Currency’s symbol.
The resulting type after applying the + operator.
Performs copy-assignment from
source.
Read more Formats the value using the given formatter.
Read more Returns the “default value” for a type.
Read more The resulting type after dereferencing.
Dereferences the value.
Source § Overloads the ‘/’ operator for Currency objects.
Allows a Currency to be divided by an i64.
The resulting type after applying the / operator.
converts from a tuple of symbol and i64
converts from a tuple of i64 and symbol
Source § Overloads the ‘*’ operator for i64.
Allows an i64 to be multiplied by a Currency.
Completes the commutative property for i64 multiplied by Currency.
The resulting type after applying the * operator.
The resulting type after applying the * operator.
Source § Multiplies with float, probably not a good idea, help appreciated.
The resulting type after applying the * operator.
Source § Overloads the ‘*’ operator for Currency objects.
Allows a Currency to be multiplied by an i64.
The resulting type after applying the * operator.
Tests for self and other values to be equal, and is used by ==.
Tests for !=. The default implementation is almost always sufficient,
and should not be overridden without very good reason.
This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more Source § 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.
The resulting type after applying the - operator.
Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from
self to
dest.
Read more Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From <T> for U chooses to do.
🔬 This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more Uses borrowed data to replace owned data, usually by cloning.
Read more The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.