From 59f552219d0d2c5d8f26951bc8aab853671ee822 Mon Sep 17 00:00:00 2001 From: ovi Date: Sun, 3 Sep 2023 14:13:20 +0200 Subject: [PATCH] Display Rational --- src/dp.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/dp.rs b/src/dp.rs index 0565b5545..e35eef6a9 100644 --- a/src/dp.rs +++ b/src/dp.rs @@ -17,6 +17,7 @@ use num_bigint::{BigInt, BigUint, TryFromBigIntError}; use num_rational::{BigRational, Ratio}; use serde::{Deserialize, Serialize}; +use std::fmt; /// Errors propagated by methods in this module. #[derive(Debug, thiserror::Error)] @@ -42,6 +43,12 @@ pub enum DpError { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct Rational(Ratio); +impl fmt::Display for Rational { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } +} + impl Rational { /// Construct a [`Rational`] number from numerator `n` and denominator `d`. Errors if denominator is zero. pub fn from_unsigned(n: T, d: T) -> Result