From 50192cbe91da765d3c09cf8e12f328b721d3cb46 Mon Sep 17 00:00:00 2001 From: superwhiskers Date: Sun, 14 Sep 2025 08:06:27 -0500 Subject: add a `Display` implementation to `Expression` this change adds a string formatter for `Expression`s using the `Display` trait. additionally, it standardizes the way `Display` implementations are written and makes some minor adjustments to the parameters used for the proptest-based test for `Expression`. Change-Id: I6a6a6964cd5c04e95341a499dcd73297ca2f514a --- crates/core/src/numerics/rational.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'crates/core/src/numerics/rational.rs') 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 fmt::Display for Rational +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) } } -- cgit 1.4.1-2-gfad0