Struct currency::Currency [] [src]

pub struct Currency {
    // some 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

fn new() -> Self

Creates a blank Currency with no symbol and 0 coin.

fn from_str(s: &str) -> Result<Currency, ParseCurrencyError>

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());

fn sign(&self) -> Sign

Returns the Sign of the BigInt holding the coins.

fn value(&self) -> &BigInt

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);
}

fn convert(&self, conversion_rate: f64, currency_symbol: char) -> Currency

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 Display for Currency

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");

fn fmt(&self, f: &mut Formatter) -> Result

impl FromStr for Currency

type Err = ParseCurrencyError

fn from_str(s: &str) -> Result<Currency, ParseCurrencyError>

impl LowerExp for Currency

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"

fn fmt(&self, f: &mut Formatter) -> Result

impl<'a, 'b> Add<&'b Currency> for &'a Currency

type Output = Currency

fn add(self, other: &'b Currency) -> Currency

impl<'a> Add<Currency> for &'a Currency

type Output = Currency

fn add(self, other: Currency) -> Currency

impl<'a> Add<&'a Currency> for Currency

type Output = Currency

fn add(self, other: &'a Currency) -> Currency

impl Add<Currency> for Currency

type Output = Currency

fn add(self, other: Currency) -> Currency

impl<'a, 'b> Sub<&'b Currency> for &'a Currency

type Output = Currency

fn sub(self, other: &'b Currency) -> Currency

impl<'a> Sub<Currency> for &'a Currency

type Output = Currency

fn sub(self, other: Currency) -> Currency

impl<'a> Sub<&'a Currency> for Currency

type Output = Currency

fn sub(self, other: &'a Currency) -> Currency

impl Sub<Currency> for Currency

type Output = Currency

fn sub(self, other: Currency) -> Currency

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

type Output = Currency

fn mul(self, other: &'b BigUint) -> Currency

impl<'a> Mul<BigUint> for &'a Currency

type Output = Currency

fn mul(self, other: BigUint) -> Currency

impl<'a> Mul<&'a BigUint> for Currency

type Output = Currency

fn mul(self, other: &'a BigUint) -> Currency

impl Mul<BigUint> for Currency

type Output = Currency

fn mul(self, other: BigUint) -> Currency

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

type Output = Currency

fn mul(self, other: &'b u8) -> Currency

impl<'a> Mul<u8> for &'a Currency

type Output = Currency

fn mul(self, other: u8) -> Currency

impl<'a> Mul<&'a u8> for Currency

type Output = Currency

fn mul(self, other: &'a u8) -> Currency

impl Mul<u8> for Currency

type Output = Currency

fn mul(self, other: u8) -> Currency

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

type Output = Currency

fn mul(self, other: &'b u16) -> Currency

impl<'a> Mul<u16> for &'a Currency

type Output = Currency

fn mul(self, other: u16) -> Currency

impl<'a> Mul<&'a u16> for Currency

type Output = Currency

fn mul(self, other: &'a u16) -> Currency

impl Mul<u16> for Currency

type Output = Currency

fn mul(self, other: u16) -> Currency

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

type Output = Currency

fn mul(self, other: &'b u32) -> Currency

impl<'a> Mul<u32> for &'a Currency

type Output = Currency

fn mul(self, other: u32) -> Currency

impl<'a> Mul<&'a u32> for Currency

type Output = Currency

fn mul(self, other: &'a u32) -> Currency

impl Mul<u32> for Currency

type Output = Currency

fn mul(self, other: u32) -> Currency

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

type Output = Currency

fn mul(self, other: &'b u64) -> Currency

impl<'a> Mul<u64> for &'a Currency

type Output = Currency

fn mul(self, other: u64) -> Currency

impl<'a> Mul<&'a u64> for Currency

type Output = Currency

fn mul(self, other: &'a u64) -> Currency

impl Mul<u64> for Currency

type Output = Currency

fn mul(self, other: u64) -> Currency

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

type Output = Currency

fn mul(self, other: &'b usize) -> Currency

impl<'a> Mul<usize> for &'a Currency

type Output = Currency

fn mul(self, other: usize) -> Currency

impl<'a> Mul<&'a usize> for Currency

type Output = Currency

fn mul(self, other: &'a usize) -> Currency

impl Mul<usize> for Currency

type Output = Currency

fn mul(self, other: usize) -> Currency

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

type Output = Currency

fn mul(self, other: &'b i8) -> Currency

impl<'a> Mul<i8> for &'a Currency

type Output = Currency

fn mul(self, other: i8) -> Currency

impl<'a> Mul<&'a i8> for Currency

type Output = Currency

fn mul(self, other: &'a i8) -> Currency

impl Mul<i8> for Currency

type Output = Currency

fn mul(self, other: i8) -> Currency

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

type Output = Currency

fn mul(self, other: &'b i16) -> Currency

impl<'a> Mul<i16> for &'a Currency

type Output = Currency

fn mul(self, other: i16) -> Currency

impl<'a> Mul<&'a i16> for Currency

type Output = Currency

fn mul(self, other: &'a i16) -> Currency

impl Mul<i16> for Currency

type Output = Currency

fn mul(self, other: i16) -> Currency

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

type Output = Currency

fn mul(self, other: &'b i32) -> Currency

impl<'a> Mul<i32> for &'a Currency

type Output = Currency

fn mul(self, other: i32) -> Currency

impl<'a> Mul<&'a i32> for Currency

type Output = Currency

fn mul(self, other: &'a i32) -> Currency

impl Mul<i32> for Currency

type Output = Currency

fn mul(self, other: i32) -> Currency

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

type Output = Currency

fn mul(self, other: &'b i64) -> Currency

impl<'a> Mul<i64> for &'a Currency

type Output = Currency

fn mul(self, other: i64) -> Currency

impl<'a> Mul<&'a i64> for Currency

type Output = Currency

fn mul(self, other: &'a i64) -> Currency

impl Mul<i64> for Currency

type Output = Currency

fn mul(self, other: i64) -> Currency

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

type Output = Currency

fn mul(self, other: &'b isize) -> Currency

impl<'a> Mul<isize> for &'a Currency

type Output = Currency

fn mul(self, other: isize) -> Currency

impl<'a> Mul<&'a isize> for Currency

type Output = Currency

fn mul(self, other: &'a isize) -> Currency

impl Mul<isize> for Currency

type Output = Currency

fn mul(self, other: isize) -> Currency

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

type Output = Currency

fn div(self, other: &'b BigUint) -> Currency

impl<'a> Div<BigUint> for &'a Currency

type Output = Currency

fn div(self, other: BigUint) -> Currency

impl<'a> Div<&'a BigUint> for Currency

type Output = Currency

fn div(self, other: &'a BigUint) -> Currency

impl Div<BigUint> for Currency

type Output = Currency

fn div(self, other: BigUint) -> Currency

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

type Output = Currency

fn div(self, other: &'b u8) -> Currency

impl<'a> Div<u8> for &'a Currency

type Output = Currency

fn div(self, other: u8) -> Currency

impl<'a> Div<&'a u8> for Currency

type Output = Currency

fn div(self, other: &'a u8) -> Currency

impl Div<u8> for Currency

type Output = Currency

fn div(self, other: u8) -> Currency

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

type Output = Currency

fn div(self, other: &'b u16) -> Currency

impl<'a> Div<u16> for &'a Currency

type Output = Currency

fn div(self, other: u16) -> Currency

impl<'a> Div<&'a u16> for Currency

type Output = Currency

fn div(self, other: &'a u16) -> Currency

impl Div<u16> for Currency

type Output = Currency

fn div(self, other: u16) -> Currency

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

type Output = Currency

fn div(self, other: &'b u32) -> Currency

impl<'a> Div<u32> for &'a Currency

type Output = Currency

fn div(self, other: u32) -> Currency

impl<'a> Div<&'a u32> for Currency

type Output = Currency

fn div(self, other: &'a u32) -> Currency

impl Div<u32> for Currency

type Output = Currency

fn div(self, other: u32) -> Currency

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

type Output = Currency

fn div(self, other: &'b u64) -> Currency

impl<'a> Div<u64> for &'a Currency

type Output = Currency

fn div(self, other: u64) -> Currency

impl<'a> Div<&'a u64> for Currency

type Output = Currency

fn div(self, other: &'a u64) -> Currency

impl Div<u64> for Currency

type Output = Currency

fn div(self, other: u64) -> Currency

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

type Output = Currency

fn div(self, other: &'b usize) -> Currency

impl<'a> Div<usize> for &'a Currency

type Output = Currency

fn div(self, other: usize) -> Currency

impl<'a> Div<&'a usize> for Currency

type Output = Currency

fn div(self, other: &'a usize) -> Currency

impl Div<usize> for Currency

type Output = Currency

fn div(self, other: usize) -> Currency

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

type Output = Currency

fn div(self, other: &'b i8) -> Currency

impl<'a> Div<i8> for &'a Currency

type Output = Currency

fn div(self, other: i8) -> Currency

impl<'a> Div<&'a i8> for Currency

type Output = Currency

fn div(self, other: &'a i8) -> Currency

impl Div<i8> for Currency

type Output = Currency

fn div(self, other: i8) -> Currency

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

type Output = Currency

fn div(self, other: &'b i16) -> Currency

impl<'a> Div<i16> for &'a Currency

type Output = Currency

fn div(self, other: i16) -> Currency

impl<'a> Div<&'a i16> for Currency

type Output = Currency

fn div(self, other: &'a i16) -> Currency

impl Div<i16> for Currency

type Output = Currency

fn div(self, other: i16) -> Currency

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

type Output = Currency

fn div(self, other: &'b i32) -> Currency

impl<'a> Div<i32> for &'a Currency

type Output = Currency

fn div(self, other: i32) -> Currency

impl<'a> Div<&'a i32> for Currency

type Output = Currency

fn div(self, other: &'a i32) -> Currency

impl Div<i32> for Currency

type Output = Currency

fn div(self, other: i32) -> Currency

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

type Output = Currency

fn div(self, other: &'b i64) -> Currency

impl<'a> Div<i64> for &'a Currency

type Output = Currency

fn div(self, other: i64) -> Currency

impl<'a> Div<&'a i64> for Currency

type Output = Currency

fn div(self, other: &'a i64) -> Currency

impl Div<i64> for Currency

type Output = Currency

fn div(self, other: i64) -> Currency

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

type Output = Currency

fn div(self, other: &'b isize) -> Currency

impl<'a> Div<isize> for &'a Currency

type Output = Currency

fn div(self, other: isize) -> Currency

impl<'a> Div<&'a isize> for Currency

type Output = Currency

fn div(self, other: &'a isize) -> Currency

impl Div<isize> for Currency

type Output = Currency

fn div(self, other: isize) -> Currency

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

type Output = Currency

fn mul(self, other: &'b f32) -> Currency

impl<'a> Mul<f32> for &'a Currency

type Output = Currency

fn mul(self, other: f32) -> Currency

impl<'a> Mul<&'a f32> for Currency

type Output = Currency

fn mul(self, other: &'a f32) -> Currency

impl Mul<f32> for Currency

type Output = Currency

fn mul(self, other: f32) -> Currency

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

type Output = Currency

fn mul(self, other: &'b f64) -> Currency

impl<'a> Mul<f64> for &'a Currency

type Output = Currency

fn mul(self, other: f64) -> Currency

impl<'a> Mul<&'a f64> for Currency

type Output = Currency

fn mul(self, other: &'a f64) -> Currency

impl Mul<f64> for Currency

type Output = Currency

fn mul(self, other: f64) -> Currency

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

type Output = Currency

fn div(self, other: &'b f32) -> Currency

impl<'a> Div<f32> for &'a Currency

type Output = Currency

fn div(self, other: f32) -> Currency

impl<'a> Div<&'a f32> for Currency

type Output = Currency

fn div(self, other: &'a f32) -> Currency

impl Div<f32> for Currency

type Output = Currency

fn div(self, other: f32) -> Currency

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

type Output = Currency

fn div(self, other: &'b f64) -> Currency

impl<'a> Div<f64> for &'a Currency

type Output = Currency

fn div(self, other: f64) -> Currency

impl<'a> Div<&'a f64> for Currency

type Output = Currency

fn div(self, other: &'a f64) -> Currency

impl Div<f64> for Currency

type Output = Currency

fn div(self, other: f64) -> Currency

impl<'a, 'b> Div<&'b Currency> for &'a Currency

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.

type Output = BigInt

fn div(self, other: &'b Currency) -> BigInt

impl<'a> Div<Currency> for &'a Currency

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.

type Output = BigInt

fn div(self, other: Currency) -> BigInt

impl<'a> Div<&'a Currency> for Currency

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.

type Output = BigInt

fn div(self, other: &'a Currency) -> BigInt

impl Div<Currency> for Currency

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.

type Output = BigInt

fn div(self, other: Currency) -> BigInt

impl Neg for Currency

type Output = Currency

fn neg(self) -> Currency

impl<'a> Neg for &'a Currency

type Output = Currency

fn neg(self) -> Currency

Derived Implementations

impl PartialOrd for Currency

fn partial_cmp(&self, __arg_0: &Currency) -> Option<Ordering>

fn lt(&self, __arg_0: &Currency) -> bool

fn le(&self, __arg_0: &Currency) -> bool

fn gt(&self, __arg_0: &Currency) -> bool

fn ge(&self, __arg_0: &Currency) -> bool

impl Eq for Currency

impl PartialEq for Currency

fn eq(&self, __arg_0: &Currency) -> bool

fn ne(&self, __arg_0: &Currency) -> bool

impl Default for Currency

fn default() -> Currency

impl Hash for Currency

fn hash<__H: Hasher>(&self, __arg_0: &mut __H)

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher

impl Clone for Currency

fn clone(&self) -> Currency

fn clone_from(&mut self, source: &Self)

impl Debug for Currency

fn fmt(&self, __arg_0: &mut Formatter) -> Result