From 6fae20e2eaedee23beda1d92c7358795dd3e5e4f Mon Sep 17 00:00:00 2001 From: Thomas BESSOU Date: Mon, 29 Jul 2024 11:38:56 +0200 Subject: [PATCH] Make `Debug` impls delegate directly to inner float Resolves #152 --- src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0cb9fe4..7df9b71 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,7 +75,7 @@ fn canonicalize_signed_zero(x: T) -> T { /// s.insert(OrderedFloat(NAN)); /// assert!(s.contains(&OrderedFloat(NAN))); /// ``` -#[derive(Debug, Default, Clone, Copy)] +#[derive(Default, Clone, Copy)] #[repr(transparent)] pub struct OrderedFloat(pub T); @@ -193,6 +193,13 @@ impl Hash for OrderedFloat { } } +impl fmt::Debug for OrderedFloat { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + impl fmt::Display for OrderedFloat { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -1090,7 +1097,7 @@ impl Num for OrderedFloat { /// // This will panic: /// let c = a + b; /// ``` -#[derive(PartialOrd, PartialEq, Debug, Default, Clone, Copy)] +#[derive(PartialOrd, PartialEq, Default, Clone, Copy)] #[repr(transparent)] pub struct NotNan(T); @@ -1177,6 +1184,13 @@ impl Hash for NotNan { } } +impl fmt::Debug for NotNan { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + impl fmt::Display for NotNan { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {