Struct currency::Currency [] [src]

pub struct Currency { /* fields omitted */ }

Represents currency through an optional symbol and amount of coin.

Every 100 coins represents a banknote. (coin: 100 => 1.00)

Methods

impl Currency
[src]

Creates a blank Currency with no symbol and 0 coin.

Parses a string literal (&str) and attempts to convert it into a currency. Returns Ok(Currency) on a successful conversion, otherwise Err(ParseCurrencyError).

Examples

use currency::Currency;

let c1 = Currency::from_str("$42.32").unwrap();
let c2 = Currency::from_str("$0.10").unwrap();
assert_eq!(c1 + c2, Currency::from_str("$42.42").unwrap());

Returns the Sign of the BigInt holding the coins.

Returns the number of coins held in the Currency as &BigInt.

Should you need ownership of the returned BigInt, call clone() on it.

Examples

extern crate num;
extern crate currency;

fn main() {
    use num::traits::ToPrimitive;
    use currency::Currency;

    let c1 = Currency::new();
    assert_eq!(c1.value().to_u32().unwrap(), 0);

    let c2 = Currency::from_str("$1.42").unwrap();
    assert_eq!(c2.value().to_u32().unwrap(), 142);
}

Returns a new Currency by multiplying the coin by the conversion rate and changing the symbol.

Examples

use currency::Currency;

let dollars = Currency::from_str("$10.00").unwrap();
let conv_rate = 0.89;
let euros = dollars.convert(0.89, '€');
assert_eq!(euros, Currency::from_str("€8.90").unwrap());

Trait Implementations

impl Debug for Currency
[src]

Formats the value using the given formatter.

impl Clone for Currency
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Hash for Currency
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl Default for Currency
[src]

Returns the "default value" for a type. Read more

impl PartialEq for Currency
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for Currency
[src]

impl PartialOrd for Currency
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Display for Currency
[src]

Allows any Currency to be displayed as a String. The format includes comma delimiting with a two digit precision decimal.

Example

use currency::Currency;

let dollars = Currency::from_str("$12.10").unwrap();
assert_eq!(dollars.to_string(), "$12.10");

let euros = Currency::from_str("£1.000").unwrap();
assert_eq!(format!("{:e}", euros), "£1.000,00");

Formats the value using the given formatter. Read more

impl FromStr for Currency
[src]

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

impl LowerExp for Currency
[src]

Identical to the implementation of Display, but replaces the "." with a ",". Access this formatting by using "{:e}".

Example

use currency::Currency;

let euros = Currency::from_str("£1000,99").unwrap();
println!("{:e}", euros);

Which prints: text "£1.000,99"

Formats the value using the given formatter.

impl<'a, 'b> Add<&'b Currency> for &'a Currency
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a> Add<Currency> for &'a Currency
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a> Add<&'a Currency> for Currency
[src]

The resulting type after applying the + operator

The method for the + operator

impl Add<Currency> for Currency
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a, 'b> Sub<&'b Currency> for &'a Currency
[src]

The resulting type after applying the - operator

The method for the - operator

impl<'a> Sub<Currency> for &'a Currency
[src]

The resulting type after applying the - operator

The method for the - operator

impl<'a> Sub<&'a Currency> for Currency
[src]

The resulting type after applying the - operator

The method for the - operator

impl Sub<Currency> for Currency
[src]

The resulting type after applying the - operator

The method for the - operator

impl<'a, 'b> Mul<&'b BigUint> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<BigUint> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a BigUint> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<BigUint> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b u8> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<u8> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a u8> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<u8> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b u16> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<u16> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a u16> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<u16> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b u32> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<u32> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a u32> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<u32> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b u64> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<u64> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a u64> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<u64> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b usize> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<usize> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a usize> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<usize> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b i8> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<i8> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a i8> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<i8> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b i16> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<i16> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a i16> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<i16> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b i32> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<i32> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a i32> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<i32> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b i64> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<i64> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a i64> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<i64> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b isize> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<isize> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a isize> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<isize> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Div<&'b BigUint> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<BigUint> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a BigUint> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<BigUint> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b u8> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<u8> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a u8> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<u8> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b u16> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<u16> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a u16> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<u16> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b u32> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<u32> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a u32> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<u32> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b u64> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<u64> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a u64> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<u64> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b usize> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<usize> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a usize> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<usize> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b i8> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<i8> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a i8> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<i8> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b i16> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<i16> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a i16> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<i16> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b i32> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<i32> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a i32> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<i32> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b i64> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<i64> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a i64> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<i64> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b isize> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<isize> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a isize> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<isize> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Mul<&'b f32> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<f32> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a f32> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<f32> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Mul<&'b f64> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<f64> for &'a Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a f64> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<f64> for Currency
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a, 'b> Div<&'b f32> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<f32> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a f32> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<f32> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b f64> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<f64> for &'a Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a f64> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<f64> for Currency
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a, 'b> Div<&'b Currency> for &'a Currency
[src]

Overloads the '/' operator between two borrowed Currency objects.

Panics

Panics if they aren't the same type of currency, as denoted by the currency's symbol.

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<Currency> for &'a Currency
[src]

Overloads the '/' operator between a borrowed Currency object and an owned one.

Panics

Panics if they aren't the same type of currency, as denoted by the currency's symbol.

The resulting type after applying the / operator

The method for the / operator

impl<'a> Div<&'a Currency> for Currency
[src]

Overloads the '/' operator between an owned Currency object and a borrowed one.

Panics

Panics if they aren't the same type of currency, as denoted by the currency's symbol.

The resulting type after applying the / operator

The method for the / operator

impl Div<Currency> for Currency
[src]

Overloads the '/' operator between two owned Currency objects.

Panics

Panics if they aren't the same type of currency, as denoted by the currency's symbol.

The resulting type after applying the / operator

The method for the / operator

impl Neg for Currency
[src]

The resulting type after applying the - operator

The method for the unary - operator

impl<'a> Neg for &'a Currency
[src]

The resulting type after applying the - operator

The method for the unary - operator