diff options
Diffstat (limited to 'crates/core/src/numerics')
-rw-r--r-- | crates/core/src/numerics/rational.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/crates/core/src/numerics/rational.rs b/crates/core/src/numerics/rational.rs index e814dbd..173e6f6 100644 --- a/crates/core/src/numerics/rational.rs +++ b/crates/core/src/numerics/rational.rs @@ -106,6 +106,16 @@ where } } +#[cfg(feature = "core-fmt")] +impl<T> fmt::Display for Rational<T> +where + T: Integer + fmt::Display, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}/{}", self.numerator, self.denominator) + } +} + /// Representation of an error that occurred within [`Rational`]. #[non_exhaustive] #[derive(Eq, PartialEq)] @@ -117,12 +127,12 @@ pub enum Error { #[cfg(feature = "core-fmt")] impl fmt::Display for Error { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - fmt.write_str("rational number construction failed")?; + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("rational number construction failed")?; let reason = match self { Error::ZeroDenominator => " because the denominator was zero", }; - fmt.write_str(reason) + f.write_str(reason) } } |