From d2b43f49f95c1e34e068d1211a034c54a81694b2 Mon Sep 17 00:00:00 2001 From: nicoo Date: Thu, 2 Jul 2020 11:34:05 +0200 Subject: [PATCH] factor::numeric::OverflowingAdd: Generate impls with a macro --- src/uu/factor/src/numeric.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/uu/factor/src/numeric.rs b/src/uu/factor/src/numeric.rs index bbfce9f26..b1f929d4b 100644 --- a/src/uu/factor/src/numeric.rs +++ b/src/uu/factor/src/numeric.rs @@ -198,21 +198,18 @@ impl Arithmetic for Montgomery { pub(crate) trait OverflowingAdd: Sized { fn overflowing_add_(self, n: Self) -> (Self, bool); } -impl OverflowingAdd for u32 { - 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) - } +macro_rules! overflowing { + ($x:ty) => { + impl OverflowingAdd for $x { + fn overflowing_add_(self, n: Self) -> (Self, bool) { + self.overflowing_add(n) + } + } + }; } +overflowing!(u32); +overflowing!(u64); +overflowing!(u128); pub(crate) trait Int: Display + Debug + PrimInt + OverflowingAdd + WrappingNeg + WrappingSub + WrappingMul