Postfix

Struct Postfix 

Source
pub struct Postfix<'a> { /* private fields */ }
Expand description

Implements Display with the currency symbol at the end.

Methods from Deref<Target = Currency>§

Source

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

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

Examples found in repository?
examples/initialization.rs (line 6)
3fn display(my_money: Currency) {
4    println!("I have {:?}!", my_money);
5    //println!("I have {}!", my_money); // doesn't compile :D
6    println!("I have {}!", my_money.postfix()); // -> "I have 47,11€!"
7    println!("I have {}!", my_money.prefix()); // -> "I have €47.11!"
8    println!()
9}
More examples
Hide additional examples
examples/display.rs (line 11)
3fn 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); // doesn't compile :D
11    println!("I have {}!", my_money.postfix()); // -> "I have 47,11€!"
12    println!("I have {}!", my_money.prefix()); // -> "I have €47.11!"
13}
Source

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

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

Examples found in repository?
examples/initialization.rs (line 7)
3fn display(my_money: Currency) {
4    println!("I have {:?}!", my_money);
5    //println!("I have {}!", my_money); // doesn't compile :D
6    println!("I have {}!", my_money.postfix()); // -> "I have 47,11€!"
7    println!("I have {}!", my_money.prefix()); // -> "I have €47.11!"
8    println!()
9}
More examples
Hide additional examples
examples/display.rs (line 12)
3fn 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); // doesn't compile :D
11    println!("I have {}!", my_money.postfix()); // -> "I have 47,11€!"
12    println!("I have {}!", my_money.prefix()); // -> "I have €47.11!"
13}
Source

pub fn as_float(&self) -> f64

Returns the value as float

§Warning, do not use this for calculation, this is for displaying only!
Source

pub fn value(&self) -> i64

Returns the inner value

Source

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

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<'a> Deref for Postfix<'a>

Source§

type Target = Currency

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Currency

Dereferences the value.
Source§

impl<'a> Display for Postfix<'a>

Allows Currencies to be displayed as Strings. The format includes no comma delimiting with a two digit precision decimal.

§Examples

use claude::Currency;

assert!(Currency{ symbol: None, value: 1210}.postfix().to_string() == "12,10");

println!("{}", Currency{ symbol: Some('€'), value: 100099}.postfix());

The last line prints the following:

"1000,99€"
Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Postfix<'a>

§

impl<'a> RefUnwindSafe for Postfix<'a>

§

impl<'a> Send for Postfix<'a>

§

impl<'a> Sync for Postfix<'a>

§

impl<'a> Unpin for Postfix<'a>

§

impl<'a> UnwindSafe for Postfix<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.