diff --git a/src/util/rational.rs b/src/util/rational.rs index 7725e05..638592b 100644 --- a/src/util/rational.rs +++ b/src/util/rational.rs @@ -73,18 +73,6 @@ impl Into for Rational { } } -impl fmt::Display for Rational { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - f.write_str(&format!("{}/{}", self.numerator(), self.denominator())) - } -} - -impl fmt::Debug for Rational { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - f.write_str(&format!("Rational({}/{})", self.numerator(), self.denominator())) - } -} - impl From for Rational { #[inline] fn from(value: f64) -> Rational { @@ -112,6 +100,12 @@ impl From for u32 { } } +impl From<(i32, i32)> for Rational { + fn from((num, den): (i32, i32)) -> Rational { + Rational::new(num, den) + } +} + impl PartialEq for Rational { fn eq(&self, other: &Rational) -> bool { if self.0 == other.0 && self.1 == other.1 { @@ -190,6 +184,18 @@ impl Div for Rational { } } +impl fmt::Display for Rational { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + f.write_str(&format!("{}/{}", self.numerator(), self.denominator())) + } +} + +impl fmt::Debug for Rational { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + f.write_str(&format!("Rational({}/{})", self.numerator(), self.denominator())) + } +} + #[inline] pub fn nearer(q: Rational, q1: Rational, q2: Rational) -> Ordering { unsafe {