From 46a5f863c88ded60d811ac88018f109db80a2c90 Mon Sep 17 00:00:00 2001 From: meh Date: Sat, 30 May 2015 17:01:38 +0200 Subject: [PATCH] util/rational: implement Debug and Display --- src/util/rational.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 {