atomr_money/lib.rs
1//! # atomr-money
2//!
3//! Exact-decimal monetary primitives for the atomr substrate.
4//!
5//! Financial consumers (NAV/GL, OMS fills, fees, PnL/Greeks) need exact money
6//! arithmetic — `f64` money is a regulatory and P&L-correctness defect. This
7//! crate provides a [`Money`] type over [`rust_decimal::Decimal`] (128-bit)
8//! behind a domain-safe API:
9//!
10//! * **No defaulted `f64` constructor.** Lossy `f64` ingestion exists only
11//! behind the off-by-default `f64-lossy` feature.
12//! * **String (de)serialization, never float.** [`Money`]/[`Price`]/[`Qty`]
13//! serialize their amount as a decimal string so nothing is lost in transit
14//! or at rest.
15//! * **Checked arithmetic.** Currency mismatch and overflow return
16//! [`MoneyError`] — never a panic or silent truncation.
17//!
18//! ```
19//! use atomr_money::{Money, Currency};
20//!
21//! let a = Money::from_str_amount("10.25", Currency::USD).unwrap();
22//! let b = Money::from_minor(75, Currency::USD); // 0.75
23//! assert_eq!(a.checked_add(&b).unwrap().to_minor(), 1100);
24//! ```
25
26#![forbid(unsafe_code)]
27
28mod currency;
29mod error;
30mod money;
31mod price_qty;
32
33pub use currency::Currency;
34pub use error::MoneyError;
35pub use money::{Money, RoundingMode};
36pub use price_qty::{Price, Qty};
37
38/// Re-export of the backing decimal type so consumers can construct exact
39/// amounts without taking a direct `rust_decimal` dependency.
40pub use rust_decimal::Decimal;