use core::ops::Sub;
pub trait CheckedSub<Rhs = Self>: Sub<Rhs> {
fn checked_sub(self, rhs: Rhs) -> Option<Self::Output>;
}
macro_rules! impl_checked_sub_for_int_ref {
($ty:ty) => {
impl CheckedSub for &$ty {
fn checked_sub(self, rhs: &$ty) -> Option<Self::Output> {
(*self).checked_sub(*rhs)
}
}
};
}
macro_rules! impl_checked_sub_for_float_ref {
($ty:ty) => {
impl CheckedSub for &$ty {
fn checked_sub(self, rhs: &$ty) -> Option<Self::Output> {
Some(self - rhs)
}
}
};
}
impl_checked_sub_for_int_ref!(i8);
impl_checked_sub_for_int_ref!(u8);
impl_checked_sub_for_int_ref!(i16);
impl_checked_sub_for_int_ref!(u16);
impl_checked_sub_for_int_ref!(i32);
impl_checked_sub_for_int_ref!(u32);
impl_checked_sub_for_int_ref!(i64);
impl_checked_sub_for_int_ref!(u64);
impl_checked_sub_for_int_ref!(i128);
impl_checked_sub_for_int_ref!(u128);
impl_checked_sub_for_int_ref!(isize);
impl_checked_sub_for_int_ref!(usize);
impl_checked_sub_for_float_ref!(f32);
impl_checked_sub_for_float_ref!(f64);