checked_pricing.rs (549B)
1 use radroots_core::pricing::QuantityPriceOps; 2 use radroots_core::{Currency, Decimal, Money, Quantity, QuantityPrice, Unit}; 3 4 fn main() -> Result<(), radroots_core::Error> { 5 let price = QuantityPrice::try_new( 6 Money::try_new("6.00".parse::<Decimal>()?, Currency::USD)?, 7 Quantity::try_new(Decimal::from(2_u32), Unit::MassKg)?, 8 )?; 9 let requested = Quantity::try_new(Decimal::from(3_u32), Unit::MassKg)?; 10 let total = price.try_cost_for_rounded(&requested)?; 11 12 assert_eq!(total.amount().to_string(), "9"); 13 Ok(()) 14 }