lucre 0.3.0

An ergonomic library for handling money.
Documentation

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.

[dependencies]
lucre = "0.1"

Usage

The Money struct is the primary interface, with the Currency struct supporting it. Currency contains constants for all current ISO 4217 currencies.

use lucre::{Money, Currency, Format};

// Create money from major or minor units
let subtotal = Money::from_major(100, &Currency::USD);
let tax = Money::from_minor(475, &Currency::USD);

// Arithmetic is available as either checked or panicking operations
let _unchecked = subtotal + tax;
let total = subtotal.checked_add(&tax).unwrap();

// The display format has sensible defaults...
assert_eq!(total.to_string(), "104.75 USD");

// ...which can be overridden
let format = Format::default().symbol();
assert_eq!(total.format_with(&format).to_string(), "$104.75");

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