Skip to main content

Module money

Module money 

Source
Expand description

Represents an amount of money in a specified currency denomination.

Money is an immutable value type for representing monetary amounts with an associated currency. It supports both positive and negative values (for debits, losses, etc.) and enforces currency consistency in arithmetic operations.

§Arithmetic behavior

OperationResultNotes
Money + MoneyMoneyPanics if currencies don’t match.
Money - MoneyMoneyPanics if currencies don’t match.
Money + DecimalDecimal
Money - DecimalDecimal
Money * DecimalDecimal
Money / DecimalDecimal
Money + f64f64
Money - f64f64
Money * f64f64
Money / f64f64
-MoneyMoney

§Currency constraints

When performing arithmetic between two Money values, both must have the same currency. Attempting to add or subtract money with different currencies raises an error.

§Immutability

Money is immutable. All arithmetic operations return new instances.

Structs§

Money
Represents an amount of money in a specified currency denomination.

Constants§

MONEY_MAX
The maximum valid money amount that can be represented.
MONEY_MIN
The minimum valid money amount that can be represented.

Statics§

MONEY_RAW_MAX
The maximum raw money integer value.
MONEY_RAW_MIN
The minimum raw money integer value.

Functions§

check_positive_money
Checks if the money value is positive.

Type Aliases§

MoneyRaw