lucre
An ergonomic Rust library for handling money.
Represent money in your applications without fussing over generics or lifetimes, while still being safe and fast. ISO 4217 currency definitions are built in.
Install
Add lucre to your Cargo.toml.
[]
= "0.8.0"
Usage
The Money struct is the primary interface, with the Currency struct supporting it.
Currency contains constants for all current ISO 4217 currencies.
use ;
Several currencies at once
Money refuses to mix currencies — + panics and comparisons answer None.
When amounts in different currencies have to travel together, put them in a
MoneyBag, which keeps each currency on its own books.
use ;
let mut wallet = new;
wallet += from_major;
wallet += from_major;
assert_eq!;
// A currency the wallet has never held answers zero, not nothing
assert_eq!;
// Both sums are available over the same iterator, so the type asked for is
// the decision: `Option<Money>` insists the currencies match, a bag keeps
// them apart
let refunds = ;
assert_eq!;
assert_eq!;
// Once the currencies disagree, only the bag still answers
let mixed = ;
assert_eq!;
Converting between currencies needs exchange rates, which are live data rather than a standard, so they are out of scope here. Iterating a bag yields each currency's balance in ISO alphabetic order, which is enough to apply rates of your own.
Maintainer
This project is maintained by Rosa Richter. For ways to contact her, see her contact page.
Contributing
Questions and contributions are absolutely welcome! Please create an issue for bugs, feature requests, or questions.
License
BSD-2-Clause-Patent © Rosa Richter