pub trait Checked: Sized {
fn checked_sub(self, other: Self) -> Option<Self>;
fn checked_add(self, other: Self) -> Option<Self>;
fn checked_mul(self, other: Self) -> Option<Self>;
}
macro_rules! impl_saturating {
($($i:ident),*) => {
$(impl Checked for $i {
fn checked_sub(self, other: Self) -> Option<Self> {
$i::checked_sub(self, other)
}
fn checked_add(self, other: Self) -> Option<Self> {
$i::checked_add(self, other)
}
fn checked_mul(self, other: Self) -> Option<Self> {
$i::checked_mul(self, other)
}
})*
};
}
impl_saturating!(
u8, i8, u16, i16, u32, i32, u64, i64, usize, isize, u128, i128
);