Open SET001 opened 9 months ago
all uX and iX types implements checked_add_signed and it would be handy to have a trait as marker for such types:
pub trait CheckedAddSigned where Self: Sized, { type RHS: TryFrom<i32>; fn checked_add_signed(self, rhs: Self::RHS) -> Option<Self>; } macro_rules! impl_checked_add_signed { ($t:ident, $rhs:ident) => { impl CheckedAddSigned for $t { type RHS = $rhs; fn checked_add_signed(self, rhs: Self::RHS) -> Option<Self> { Self::checked_add_signed(self, rhs) } } }; } impl_checked_add_signed!(u8, i8); impl_checked_add_signed!(u16, i16); impl_checked_add_signed!(u32, i32); impl_checked_add_signed!(u64, i64); impl_checked_add_signed!(usize, isize);
all uX and iX types implements checked_add_signed and it would be handy to have a trait as marker for such types: