From Macro to tortured Generic

This commit is contained in:
Timothy Warren 2020-02-14 12:30:09 -05:00
parent 16741c8c4d
commit d20cb06c87

View File

@ -52,28 +52,21 @@ impl<T: Unsigned> Frac<T> {
} }
} }
macro_rules! impl_mul { impl<T: Unsigned + Mul<Output = T>> Mul for Frac<T> {
($( $Type: ty ),* ) => { type Output = Self;
$(
impl Mul for Frac<$Type> {
type Output = Self;
fn mul(self, rhs: Self) -> Self { fn mul(self, rhs: Self) -> Self {
let numer = self.numer * rhs.numer; let numer = self.numer * rhs.numer;
let denom = self.denom * rhs.denom; let denom = self.denom * rhs.denom;
// Figure out the sign // Figure out the sign
if self.sign != rhs.sign { if self.sign != rhs.sign {
Self::new_neg(numer, denom) Self::new_neg(numer, denom)
} else { } else {
Self::new(numer, denom) Self::new(numer, denom)
} }
} }
}
)*
};
} }
impl_mul!(u8, u16, u32, u64, usize, u128);
impl<T: Unsigned> Neg for Frac<T> { impl<T: Unsigned> Neg for Frac<T> {
type Output = Self; type Output = Self;