Struct bill::Currency

source ยท
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: i64

value in the smallest possible unit

Implementationsยง

sourceยง

impl Currency

source

pub fn new() -> Currency

Creates a blank Currency as Currency(None, 0)

Examples
let mut c = Currency::new();
source

pub fn from_value(value: i64) -> Currency

Initialize from i64

source

pub fn postfix(&self) -> Postfix<'_>

Returns an object that implements Display for different methods of printing currency.

source

pub fn prefix(&self) -> Prefix<'_>

Returns an object that implements Display for different methods of printing currency.

source

pub fn as_float(&self) -> f64

source

pub fn value(&self) -> i64

Returns the inner value

source

pub fn symbol(&self) -> Option<char>

Returns the inner symbol

Methods from Deref<Target = i64>ยง

1.43.0 ยท source

pub const MIN: i64 = -9_223_372_036_854_775_808i64

1.43.0 ยท source

pub const MAX: i64 = 9_223_372_036_854_775_807i64

1.53.0 ยท source

pub const BITS: u32 = 64u32

Trait Implementationsยง

sourceยง

impl Add<Currency> 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.

ยง

type Output = Currency

The resulting type after applying the + operator.
sourceยง

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

Performs the + operation. Read more
sourceยง

impl Clone for Currency

sourceยง

fn clone(&self) -> Currency

Returns a copy of the value. Read more
1.0.0 ยท sourceยง

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

Performs copy-assignment from source. Read more
sourceยง

impl Debug for Currency

sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
sourceยง

impl Default for Currency

sourceยง

fn default() -> Currency

Returns the โ€œdefault valueโ€ for a type. Read more
sourceยง

impl Deref for Currency

Required for DerefMut

ยง

type Target = i64

The resulting type after dereferencing.
sourceยง

fn deref(&self) -> &i64

Dereferences the value.
sourceยง

impl Div<i64> for Currency

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.
sourceยง

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

Performs the / operation. Read more
sourceยง

impl From<(char, i64)> for Currency

sourceยง

fn from(tpl: (char, i64)) -> Currency

converts from a tuple of symbol and i64

sourceยง

impl From<(i64, char)> for Currency

sourceยง

fn from(tpl: (i64, char)) -> Currency

converts from a tuple of i64 and symbol

sourceยง

impl From<i64> for Currency

sourceยง

fn from(value: i64) -> Currency

converts from a i64

sourceยง

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.

ยง

type Output = Currency

The resulting type after applying the * operator.
sourceยง

fn mul(self, rhs: Currency) -> Currency

Performs the * operation. Read more
sourceยง

impl Mul<f64> for Currency

Multiplies with float, probably not a good idea, help appreciated.

ยง

type Output = Currency

The resulting type after applying the * operator.
sourceยง

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

Performs the * operation. Read more
sourceยง

impl Mul<i64> for Currency

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.
sourceยง

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

Performs the * operation. Read more
sourceยง

impl PartialEq<Currency> for Currency

sourceยง

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 ยท sourceยง

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
sourceยง

impl PartialOrd<Currency> for Currency

sourceยง

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 ยท sourceยง

fn lt(&self, other: &Rhs) -> bool

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

fn le(&self, other: &Rhs) -> bool

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

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl Serialize for Currency

sourceยง

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
sourceยง

impl Sub<Currency> 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.

ยง

type Output = Currency

The resulting type after applying the - operator.
sourceยง

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

Performs the - operation. Read more
sourceยง

impl Copy for Currency

sourceยง

impl Eq for Currency

sourceยง

impl StructuralEq for Currency

sourceยง

impl StructuralPartialEq for Currency

Auto Trait Implementationsยง

Blanket Implementationsยง

sourceยง

impl<T> Any for Twhere T: 'static + ?Sized,

sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
sourceยง

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable ยท sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
sourceยง

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable ยท sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
sourceยง

impl<T> From<T> for T

const: unstable ยท sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

sourceยง

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable ยท sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

sourceยง

impl<T> ToOwned for Twhere T: Clone,

ยง

type Owned = T

The resulting type after obtaining ownership.
sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
sourceยง

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

ยง

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable ยท sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
sourceยง

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

ยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable ยท sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.