Expand description
Domain types for reasoning about money and food.
money-food keeps monetary arithmetic in integer minor units and makes
currency mismatches explicit. It connects prices to menu items, menus to
stores, and orders to taxes, service charges, and budgets.
§Example
use money_food::{Currency, Menu, MenuItem, Money, OrderLine, Rate, Store};
let jpy = Currency::new("JPY")?;
let ramen = MenuItem::new("ramen", "Ramen", Money::from_minor(900, jpy)?)?
.with_value_score(90);
let gyoza = MenuItem::new("gyoza", "Gyoza", Money::from_minor(450, jpy)?)?;
let store = Store::new("Rust Ramen", Menu::new(jpy, [ramen, gyoza])?)?;
let quote = store.quote(
[OrderLine::new("ramen", 1)?],
Rate::from_basis_points(1_000)?, // 10% tax
Rate::ZERO,
Some(Money::from_minor(1_000, jpy)?),
)?;
assert_eq!(quote.total().minor_units(), 990);
assert_eq!(quote.remaining_budget().unwrap().minor_units(), 10);Structs§
- Currency
- A validated, ISO-style three-letter currency code.
- Menu
- A currency-consistent collection of menu items.
- Menu
Item - A purchasable food or drink on a menu.
- Money
- A non-negative amount held in a currency’s minor units.
- Order
Line - A requested menu item and quantity.
- Quote
- An order’s fully calculated monetary result.
- Rate
- A tax, fee, or service rate expressed in basis points (1/100 of 1%).
- Store
- A named store that owns a menu and can calculate order quotes.
Enums§
- Error
- Errors produced by the domain model.