#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct Cents(i64); impl Cents { pub fn checked_add(self, other: Cents) -> Option<Cents> { self.0.checked_add(other.0).map(Cents) } // splits without losing a cent: the first `rem` parts get one more pub fn split(self, parts: u32) -> Vec<Cents> { let n = i64::from(parts.max(1)); let (base, rem) = (self.0.div_euclid(n), self.0.rem_euclid(n)); (0..n).map(|i| Cents(base + i64::from(i < rem))).collect() } }