diff --git a/agb/src/number.rs b/agb/src/number.rs index 218c39a8..004f5154 100644 --- a/agb/src/number.rs +++ b/agb/src/number.rs @@ -12,55 +12,79 @@ impl From for Num { } } -impl Add for Num { +impl Add for Num +where + T: Into>, +{ type Output = Self; - fn add(self, rhs: Num) -> Self::Output { - Num(self.0 + rhs.0) + fn add(self, rhs: T) -> Self::Output { + Num(self.0 + rhs.into().0) } } -impl AddAssign for Num { - fn add_assign(&mut self, rhs: Self) { - self.0 += rhs.0 +impl AddAssign for Num +where + T: Into>, +{ + fn add_assign(&mut self, rhs: T) { + self.0 += (*self + rhs.into()).0 } } -impl Sub for Num { +impl Sub for Num +where + T: Into>, +{ type Output = Self; - fn sub(self, rhs: Num) -> Self::Output { - Num(self.0 - rhs.0) + fn sub(self, rhs: T) -> Self::Output { + Num(self.0 - rhs.into().0) } } -impl SubAssign for Num { - fn sub_assign(&mut self, rhs: Self) { - self.0 -= rhs.0 +impl SubAssign for Num +where + T: Into>, +{ + fn sub_assign(&mut self, rhs: T) { + self.0 = (*self - rhs.into()).0 } } -impl Mul for Num { +impl Mul for Num +where + T: Into>, +{ type Output = Self; - fn mul(self, rhs: Num) -> Self::Output { - Num((self.0 * rhs.0) >> N) + fn mul(self, rhs: T) -> Self::Output { + Num((self.0 * rhs.into().0) >> N) } } -impl MulAssign for Num { - fn mul_assign(&mut self, rhs: Self) { - self.0 = (*self * rhs).0 +impl MulAssign for Num +where + T: Into>, +{ + fn mul_assign(&mut self, rhs: T) { + self.0 = (*self * rhs.into()).0 } } -impl Div for Num { +impl Div for Num +where + T: Into>, +{ type Output = Self; - fn div(self, rhs: Num) -> Self::Output { - Num((self.0 << N) / rhs.0) + fn div(self, rhs: T) -> Self::Output { + Num((self.0 << N) / rhs.into().0) } } -impl DivAssign for Num { - fn div_assign(&mut self, rhs: Self) { - self.0 = (*self / rhs).0 +impl DivAssign for Num +where + T: Into>, +{ + fn div_assign(&mut self, rhs: T) { + self.0 = (*self / rhs.into()).0 } } @@ -92,16 +116,16 @@ impl Num { fn test_numbers(_gba: &mut super::Gba) { // test addition let n: Num<8> = 1.into(); - assert_eq!(n + 2.into(), 3.into(), "testing that 1 + 2 == 3"); + assert_eq!(n + 2, 3.into(), "testing that 1 + 2 == 3"); // test multiplication let n: Num<8> = 5.into(); - assert_eq!(n * 3.into(), 15.into(), "testing that 5 * 3 == 15"); + assert_eq!(n * 3, 15.into(), "testing that 5 * 3 == 15"); // test division let n: Num<8> = 30.into(); let p: Num<8> = 3.into(); - assert_eq!(n / 20.into(), p / 2.into(), "testing that 30 / 20 == 3 / 2"); + assert_eq!(n / 20, p / 2, "testing that 30 / 20 == 3 / 2"); assert_ne!(n, p, "testing that 30 != 3"); }