Skip to content

Commit 0efe673

Browse files
committed
Make Debug impls delegate directly to inner float
Resolves #152
1 parent d76512a commit 0efe673

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn canonicalize_signed_zero<T: FloatCore>(x: T) -> T {
7575
/// s.insert(OrderedFloat(NAN));
7676
/// assert!(s.contains(&OrderedFloat(NAN)));
7777
/// ```
78-
#[derive(Debug, Default, Clone, Copy)]
78+
#[derive(Default, Clone, Copy)]
7979
#[repr(transparent)]
8080
pub struct OrderedFloat<T>(pub T);
8181

@@ -193,6 +193,13 @@ impl<T: FloatCore> Hash for OrderedFloat<T> {
193193
}
194194
}
195195

196+
impl<T: FloatCore + fmt::Debug> fmt::Debug for OrderedFloat<T> {
197+
#[inline]
198+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
199+
self.0.fmt(f)
200+
}
201+
}
202+
196203
impl<T: FloatCore + fmt::Display> fmt::Display for OrderedFloat<T> {
197204
#[inline]
198205
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -1090,7 +1097,7 @@ impl<T: FloatCore + Num> Num for OrderedFloat<T> {
10901097
/// // This will panic:
10911098
/// let c = a + b;
10921099
/// ```
1093-
#[derive(PartialOrd, PartialEq, Debug, Default, Clone, Copy)]
1100+
#[derive(PartialOrd, PartialEq, Default, Clone, Copy)]
10941101
#[repr(transparent)]
10951102
pub struct NotNan<T>(T);
10961103

@@ -1177,6 +1184,13 @@ impl<T: FloatCore> Hash for NotNan<T> {
11771184
}
11781185
}
11791186

1187+
impl<T: FloatCore + fmt::Debug> fmt::Debug for NotNan<T> {
1188+
#[inline]
1189+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1190+
self.0.fmt(f)
1191+
}
1192+
}
1193+
11801194
impl<T: FloatCore + fmt::Display> fmt::Display for NotNan<T> {
11811195
#[inline]
11821196
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

0 commit comments

Comments
 (0)