1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-03 06:27:45 +00:00

factor::numeric::OverflowingAdd: Generate impls with a macro

This commit is contained in:
nicoo 2020-07-02 11:34:05 +02:00
parent b25c77c5f9
commit d2b43f49f9

View file

@ -198,21 +198,18 @@ impl<T: DoubleInt> Arithmetic for Montgomery<T> {
pub(crate) trait OverflowingAdd: Sized { pub(crate) trait OverflowingAdd: Sized {
fn overflowing_add_(self, n: Self) -> (Self, bool); fn overflowing_add_(self, n: Self) -> (Self, bool);
} }
impl OverflowingAdd for u32 { macro_rules! overflowing {
fn overflowing_add_(self, n: Self) -> (Self, bool) { ($x:ty) => {
self.overflowing_add(n) impl OverflowingAdd for $x {
} fn overflowing_add_(self, n: Self) -> (Self, bool) {
} self.overflowing_add(n)
impl OverflowingAdd for u64 { }
fn overflowing_add_(self, n: Self) -> (Self, bool) { }
self.overflowing_add(n) };
}
}
impl OverflowingAdd for u128 {
fn overflowing_add_(self, n: Self) -> (Self, bool) {
self.overflowing_add(n)
}
} }
overflowing!(u32);
overflowing!(u64);
overflowing!(u128);
pub(crate) trait Int: pub(crate) trait Int:
Display + Debug + PrimInt + OverflowingAdd + WrappingNeg + WrappingSub + WrappingMul Display + Debug + PrimInt + OverflowingAdd + WrappingNeg + WrappingSub + WrappingMul