Closed oti-dev closed 1 year ago
Implement Neg trait for Money to enable unary - operator -- it's fairly simple, and might come handy in some scenarios, e.g. tests.
Money
-
For instance, to make my code more clear I used a helper method in my tests:
fn usd(major: i64) -> Money<'static, Currency> { use rusty_money::iso::USD; Money::from_major(major, USD) }
Right now these assertions work fine:
assert_eq!(total, -1 * usd(10)) assert_eq!(total, usd(-10))
but I don't like neither. This feels more natural to me:
assert_eq!(total, -usd(10))
Implement Neg trait for
Money
to enable unary-
operator -- it's fairly simple, and might come handy in some scenarios, e.g. tests.For instance, to make my code more clear I used a helper method in my tests:
Right now these assertions work fine:
but I don't like neither. This feels more natural to me: