diff --git a/src/util/rational.rs b/src/util/rational.rs index 170e76d..546f3d0 100644 --- a/src/util/rational.rs +++ b/src/util/rational.rs @@ -1,10 +1,11 @@ use std::cmp::Ordering; use std::ops::{Add, Sub, Mul, Div}; +use std::fmt; use libc::{c_int, int64_t}; use ffi::*; -#[derive(Eq, PartialEq, Copy, Clone, Debug)] +#[derive(Eq, PartialEq, Copy, Clone)] pub struct Rational(pub AVRational); impl Rational { @@ -40,6 +41,18 @@ impl 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 { fn from(value: f64) -> Rational { unsafe {