Struct currency::Currency
[−]
[src]
pub struct Currency(pub Option<char>, pub i64);
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"
Methods
impl Currency
[src]
fn new() -> Currency
Creates a blank Currency as Currency(None, 0)
Examples
use currency::Currency; let mut c = Currency::new();
fn from_string(s: &str) -> Currency
Uses a Regular Expression to parse a string literal (&str) and turns it into a currency.
If the currency is intended to be a negative amount, ensure the '-' is the first character in the string. The Regex recognizes European notation (€1,00)
Examples
use currency::Currency; assert!(Currency::from_string("$4.32") == Currency(Some('$'), 432)); assert!(Currency::from_string("-$4.32") == Currency(Some('$'), -432)); assert!(Currency::from_string("424.44") == Currency(None, 42444)); assert!(Currency::from_string("£12,00") == Currency(Some('£'), 1200)); assert!(Currency::from_string("¥12") == Currency(Some('¥'), 1200));
Failures
Fails if the string is not formatted correctly.
Panics
Panics if a number fails to be parsed; this only occurs if the string argument has no numbers in it.
Trait Implementations
impl Debug for Currency
[src]
impl Display for Currency
[src]
Allows Currencies to be displayed as Strings The format includes no comma delimiting with a two digit precision decimal
Examples
use currency::Currency; assert!(Currency(Some('$'), 1210).to_string() == "$12.10"); assert!(Currency(None, 1210).to_string() == "12.10"); println!("{}", Currency(Some('$'), 100099));
The last line prints the following:
text "$1000.99"
impl LowerExp for Currency
[src]
Identical to the implementation of Display, but replaces the "." with a "," Access this formating by using "{:e}"
Examples
use currency::Currency; println!("{:e}", Currency(Some('£'), 100099));
The last line prints the following:
text "£1000,99"
impl PartialEq<Currency> for Currency
[src]
Overloads the '==' operator for Currency objects.
Panics
Panics if the two comparators are different types of currency, as denoted by the Currency's symbol.
fn eq(&self, rhs: &Currency) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, rhs: &Currency) -> bool
This method tests for !=
.
impl PartialOrd<Currency> for Currency
[src]
Overloads the order operators for Currency objects.
These operators include '<', '<=', '>', and '>='.
Panics
Panics if the two comparators are different types of currency, as denoted by the Currency's symbol.
fn partial_cmp(&self, rhs: &Currency) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, rhs: &Currency) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, rhs: &Currency) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, rhs: &Currency) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, rhs: &Currency) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Add for Currency
[src]
Overloads the '+' operator for Currency objects.
Panics
Panics if the two addends are different types of currency, as denoted by the Currency's symbol.
type Output = Currency
The resulting type after applying the +
operator
fn add(self, rhs: Currency) -> Currency
The method for the +
operator
impl Sub for Currency
[src]
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.
type Output = Currency
The resulting type after applying the -
operator
fn sub(self, rhs: Currency) -> Currency
The method for the -
operator
impl Mul<i64> for Currency
[src]
Overloads the '*' operator for Currency objects.
Allows a Currency to be multiplied by an i64.
type Output = Currency
The resulting type after applying the *
operator
fn mul(self, rhs: i64) -> Currency
The method for the *
operator
impl Div<i64> for Currency
[src]
Overloads the '/' operator for Currency objects.
Allows a Currency to be divided by an i64.
type Output = Currency
The resulting type after applying the /
operator
fn div(self, rhs: i64) -> Currency
The method for the /
operator
impl Copy for Currency
[src]
Allows Currencies to be copied, rather than using move semantics.
impl Clone for Currency
[src]
fn clone(&self) -> Currency
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more