Skip to content

Commit

Permalink
Merge pull request #153 from Ten0/direct_debug_impl
Browse files Browse the repository at this point in the history
Make `Debug` impls delegate directly to inner float
  • Loading branch information
mbrubeck authored Jul 29, 2024
2 parents d76512a + 6fae20e commit 2ef58c4
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn canonicalize_signed_zero<T: FloatCore>(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<T>(pub T);

Expand Down Expand Up @@ -193,6 +193,13 @@ impl<T: FloatCore> Hash for OrderedFloat<T> {
}
}

impl<T: fmt::Debug> fmt::Debug for OrderedFloat<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}

impl<T: FloatCore + fmt::Display> fmt::Display for OrderedFloat<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -1090,7 +1097,7 @@ impl<T: FloatCore + Num> Num for OrderedFloat<T> {
/// // 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>(T);

Expand Down Expand Up @@ -1177,6 +1184,13 @@ impl<T: FloatCore> Hash for NotNan<T> {
}
}

impl<T: fmt::Debug> fmt::Debug for NotNan<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}

impl<T: FloatCore + fmt::Display> fmt::Display for NotNan<T> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down

0 comments on commit 2ef58c4

Please sign in to comment.