Skip to main content

BaseMoney

Trait BaseMoney 

Source
pub trait BaseMoney:
    Sized
    + Debug
    + Display
    + Clone
    + PartialOrd
    + PartialEq
    + FromStr {
Show 20 methods // Required methods fn currency(&self) -> Currency; fn amount(&self) -> Decimal; fn round(self) -> Self; // Provided methods fn name(&self) -> &str { ... } fn symbol(&self) -> &str { ... } fn code(&self) -> &str { ... } fn numeric_code(&self) -> i32 { ... } fn minor_unit(&self) -> u16 { ... } fn minor_amount(&self) -> MoneyResult<i128> { ... } fn thousand_separator(&self) -> &'static str { ... } fn decimal_separator(&self) -> &'static str { ... } fn is_zero(&self) -> bool { ... } fn is_positive(&self) -> bool { ... } fn is_negative(&self) -> bool { ... } fn format_code(&self) -> String { ... } fn format_symbol(&self) -> String { ... } fn format_code_minor(&self) -> MoneyResult<String> { ... } fn format_symbol_minor(&self) -> MoneyResult<String> { ... } fn display(&self) -> String { ... } fn countries(&self) -> Option<Vec<Country>> { ... }
}
Expand description

BaseMoney is the base trait for dealing with money type.

Required Methods§

Source

fn currency(&self) -> Currency

Get currency of money

Source

fn amount(&self) -> Decimal

Get amount of money

Source

fn round(self) -> Self

Round money using Currency’s rounding strategy to the scale of currency’s minor unit

Provided Methods§

Source

fn name(&self) -> &str

Get currency name

Source

fn symbol(&self) -> &str

Get money symbol

Source

fn code(&self) -> &str

Get money ISO 4217 code

Source

fn numeric_code(&self) -> i32

Get currency ISO 4217 numeric code

Source

fn minor_unit(&self) -> u16

Get money minor unit

Source

fn minor_amount(&self) -> MoneyResult<i128>

Get money amount in its smallest unit

Source

fn thousand_separator(&self) -> &'static str

Get money thousands separator

Source

fn decimal_separator(&self) -> &'static str

Get money decimal separator

Source

fn is_zero(&self) -> bool

Check if amount is 0

Source

fn is_positive(&self) -> bool

Check if sign is +

Source

fn is_negative(&self) -> bool

Check if sign is -

Source

fn format_code(&self) -> String

Format money with code along with thousands and decimal separators. Example: USD 1,234.45

Source

fn format_symbol(&self) -> String

Format money with symbol along with thousands and decimal separators. Example: $1,234.45

Source

fn format_code_minor(&self) -> MoneyResult<String>

Format money with code in the smallest unit along with thousands separators. Example USD 1,234.45 –> USD 123,445 ¢ If the currency has no minor unit symbol, it defaults to “minor”. You can set the minor unit symbol in Currency type’s setter.

Source

fn format_symbol_minor(&self) -> MoneyResult<String>

Format money with code in the smallest unit along with thousands separators. Example $1,234.45 –> $123,445 ¢ If the currency has no minor unit symbol, it defaults to “minor”. You can set the minor unit symbol in Currency type’s setter.

Source

fn display(&self) -> String

Default display of money

Source

fn countries(&self) -> Option<Vec<Country>>

Get countries using this currency

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§