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 {
($( $Type: ty ),* ) => {
$(
impl Mul for Frac<$Type> {
type Output = Self;
impl<T: Unsigned + Mul<Output = T>> Mul for Frac<T> {
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<T: Unsigned> Neg for Frac<T> {
type Output = Self;