Skip to content

Commit

Permalink
Display Rational
Browse files Browse the repository at this point in the history
  • Loading branch information
ooovi committed Sep 3, 2023
1 parent 3ac128d commit 59f5522
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -42,6 +43,12 @@ pub enum DpError {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Rational(Ratio<BigUint>);

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<T>(n: T, d: T) -> Result<Self, DpError>
Expand Down

0 comments on commit 59f5522

Please sign in to comment.