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
| Operation | Result | Notes |
|---|---|---|
Money + Money | Money | Panics if currencies don’t match. |
Money - Money | Money | Panics if currencies don’t match. |
Money + Decimal | Decimal | |
Money - Decimal | Decimal | |
Money * Decimal | Decimal | |
Money / Decimal | Decimal | |
Money + f64 | f64 | |
Money - f64 | f64 | |
Money * f64 | f64 | |
Money / f64 | f64 | |
-Money | Money |
§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
valueis positive.