diff options
author | superwhiskers <[email protected]> | 2025-09-14 08:06:27 -0500 |
---|---|---|
committer | superwhiskers <[email protected]> | 2025-09-15 10:55:10 -0500 |
commit | 50192cbe91da765d3c09cf8e12f328b721d3cb46 (patch) | |
tree | 345e69ef1141c26774677982fe5eaba875dbbbe0 /crates/core/src/numerics | |
parent | 83751efd734999fc11316a66317250ca53e76726 (diff) | |
download | azimuth-50192cbe91da765d3c09cf8e12f328b721d3cb46.tar.gz azimuth-50192cbe91da765d3c09cf8e12f328b721d3cb46.tar.bz2 azimuth-50192cbe91da765d3c09cf8e12f328b721d3cb46.zip |
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
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) } } |