paft-money

Crates.iopaft-money
lib.rspaft-money
version0.7.1
created_at2025-10-02 11:39:25.739087+00
updated_at2025-10-31 17:56:02.399067+00
descriptionCurrency and money primitives for the paft ecosystem.
homepagehttps://github.com/paft-rs/paft
repositoryhttps://github.com/paft-rs/paft
max_upload_size
id1864275
size217,330
G. Ramistella (gramistella)

documentation

https://docs.rs/paft-money

README

paft-money

Currency and money primitives for the paft ecosystem.

Crates.io Docs.rs

  • Currency with ISO 4217 integration and extensible fallback
  • Money with safe arithmetic and explicit conversions via ExchangeRate
  • Backend-agnostic decimals (default rust_decimal, optional bigdecimal feature)
  • Runtime currency metadata overlays for non-ISO minor units (e.g., XAU, XDR)

Install

Prefer the facade crate for most applications:

[dependencies]
paft = "0.7.1"

Advanced (direct dependency, default backend):

[dependencies]
paft-money = "0.7.1"

Alternate decimal backend:

[dependencies]
paft-money = { version = "0.7.1", features = ["bigdecimal"] }

With DataFrame integration or panicking ops:

[dependencies]
paft-money = { version = "0.7.1", features = ["dataframe", "panicking-money-ops"] }

Features

  • bigdecimal: switch to arbitrary precision decimals
  • dataframe: Polars integration (ToDataFrame/ToDataFrameVec)
  • panicking-money-ops: opt-in operator overloading that panics on invalid operations
  • money-formatting: locale-aware formatting and strict parsing for Money

Quickstart

use iso_currency::Currency as IsoCurrency;
use paft_money::{Currency, Money};

let price = Money::from_canonical_str("12.34", Currency::Iso(IsoCurrency::USD))?;
let tax   = Money::from_canonical_str("1.23",  Currency::Iso(IsoCurrency::USD))?;
let total = price.try_add(&tax)?;
assert_eq!(total.format(), "13.57 USD");
# Ok::<(), paft_money::MoneyError>(())

Locale-aware formatting

When you enable the optional money-formatting feature, localized output lives behind explicit APIs so the canonical Display remains stable ("<amount> <CODE>").

# #[cfg(feature = "money-formatting")]
# {
use iso_currency::Currency as IsoCurrency;
use paft_money::{Currency, Locale, Money};

let eur = Money::from_canonical_str("1234.56", Currency::Iso(IsoCurrency::EUR)).unwrap();
assert_eq!(format!("{eur}"), "1234.56 EUR");
assert_eq!(eur.format_with_locale(Locale::EnEu).unwrap(), "€1.234,56");
assert_eq!(format!("{}", eur.localized(Locale::EnEu).with_code()), "€1.234,56 EUR");

let parsed =
    Money::from_str_locale("€1.234,56", Currency::Iso(IsoCurrency::EUR), Locale::EnEu).unwrap();
assert_eq!(parsed.format(), "1234.56 EUR");
# }

Links

Commit count: 38

cargo fmt