use super::funejson::Value; use super::math_clamp::clamp; use super::money_amount::{assert_same_currency, money, money_from_value, money_to_value, Money}; /// `amount` held within `min..=max`, all three in one currency. Bounds the /// wrong way round are an error (from math.clamp), not an answer: capping a /// refund at the original charge with the bounds swapped is a bug to surface. /// /// # Panics /// Panics on mixed currencies or if `min` is above `max`. pub fn clamp_money(amount: &Money, min: &Money, max: &Money) -> Money { assert_same_currency(amount, min); assert_same_currency(amount, max); money(clamp(amount.minor, min.minor, max.minor), &amount.currency) } pub fn fune_vector(args: &[Value]) -> Value { money_to_value(&clamp_money( &money_from_value(&args[0]), &money_from_value(&args[1]), &money_from_value(&args[2]), )) }