simple_money-0.3.0 has been yanked.
Brief description
"Down-to-earth" (explained further below) money [^fowler] and currency implementation written in Rust.
See further below for more detailed design considerations. [^fowler]: Money consists of an amount and a Currency, as described by Martin Fowler in his Money EAA Pattern.
Usage
// You create a Currency either with a string code ...
let eur = new?;
// ... or a byte array ...
let kwt = new_using_bytes?;
// ... you need a byte array also to create a constant (compiler doesn't allow unwrap) ...
const EUR: Currency = new_using_bytes_const;
// ... and use either to instantiate Money instances:
let money1 = Money ;
let money2 = Money ;
let result = money1 + money2;
Other implementations
Simple Money has similar implementations in other programming languages. There's a Simple Money project page on BitBucket, but I haven't published all of them.
Features and design considerations
Features in common with all implementations: see Design Considerations
Comparison to similar libraries
Here are two alternatives I've found:
- steel-cent
- uses an i64 for the amount, just like this implementation
- has the same precision as the minor amount allows (no "half Cents")
- its currency has the
Copytrait and is as small as mine - the ISO currencies are provided, but IntelliJ's Rust plugin fails to see them (works in the terminal though)
- rusty-money:
- uses its own 128 representation for the amount
- has more precision than available by the minor amount
- its currency...
- has lots of fields, ...
- ... but the ISO currencies are provided ready to use
- has the
Copytrait, but is eighty bytes in size
- is bristling with features (e.g. exchange rates?)