Skip to main content

Crate kamu_money_core

Crate kamu_money_core 

Source
Expand description

Exact ISO 4217 money with compile-time currency identity.

Money<USD> and Money<IDR> are different types, so cross-currency arithmetic is a compile error. Addition and subtraction are exact. Division returns a Division and requires a named residue decision before releasing its quotient.

§Start here

use kamu_money_core::{Money, iso::USD};

let whole = Money::<USD>::try_from_major(10)?;
let parts = whole.allocate(&[1, 1, 1])?;
assert_eq!(Money::<USD>::try_sum(parts)?, whole);

The crate root holds the common path. Browse deeper only when needed:

  • locale and text own display and canonical text;
  • errors groups narrow operation errors;
  • advanced exposes raw-unit kernels, domain constants, residue internals, and stable hashing;
  • feature-gated wire and adapters expose boundary integrations.

§What this crate is not

It represents amounts. It does not model tax, accounting rules, or FX policy, and exactness does not stand in for any of them: an amount this crate can hold and carry without error is still only as right as the decision that produced it. Each type states its own guarantees beside the things it deliberately does not guarantee — start with Money and Rate.

Re-exports§

pub use errors::MoneyError;
pub use iso::Iso4217;

Modules§

adapters
Optional database integrations.
advanced
Raw-unit and persistence surfaces for specialist integrations.
errors
Narrow errors, grouped by the operation that can return them.
iso
ISO 4217 currency identity. One register, three consumers.
locale
Locale-aware display: symbol, grouping, and a minimum fraction width.
text
The canonical text form: "<ISO> <amount>", one trim rule, one parser.
wireserde
Serde wire formats.

Macros§

money
Build a Money constant from a decimal literal, checked at compile time.

Structs§

Division
A quotient and residue that must be resolved together.
Money
A monetary quantity: units counts 10^-18 of a currency unit.
Rate
A directed FX rate: how many Quote units one Base unit buys.
Residue
Canonical units moved by a rounding operation.
SplitParts
The lazy half of Money::split, returned by Money::split.

Enums§

Rounding
How to resolve a division that does not divide evenly.

Traits§

StaticCurrency
A currency, known at compile time. Implemented by the generated ISO register, never by hand — and enforced, not requested: the crate-private sealing supertrait is unnameable downstream.