From d20cb06c8743269b38111a2223caceb290a778d3 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 14 Feb 2020 12:30:09 -0500 Subject: [PATCH] From Macro to tortured Generic --- src/rational.rs | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/rational.rs b/src/rational.rs index b3dc3ac..2f1100a 100644 --- a/src/rational.rs +++ b/src/rational.rs @@ -52,28 +52,21 @@ impl Frac { } } -macro_rules! impl_mul { - ($( $Type: ty ),* ) => { - $( - impl Mul for Frac<$Type> { - type Output = Self; +impl> Mul for Frac { + type Output = Self; - fn mul(self, rhs: Self) -> Self { - let numer = self.numer * rhs.numer; - let denom = self.denom * rhs.denom; + fn mul(self, rhs: Self) -> Self { + let numer = self.numer * rhs.numer; + let denom = self.denom * rhs.denom; - // Figure out the sign - if self.sign != rhs.sign { - Self::new_neg(numer, denom) - } else { - Self::new(numer, denom) - } - } - } - )* - }; + // Figure out the sign + if self.sign != rhs.sign { + Self::new_neg(numer, denom) + } else { + Self::new(numer, denom) + } + } } -impl_mul!(u8, u16, u32, u64, usize, u128); impl Neg for Frac { type Output = Self;