Skip to content

Commit bfabcc9

Browse files
committed
Implement Borrow for NotNan
This is limited to `NotNan<f32>` and `NotNan<f64>` because it would be incorrect for custom numeric types that have their own `Hash` implementations that do not match the one for `NotNan`. Fixes #98
1 parent 5cf18fe commit bfabcc9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extern crate std;
99
#[cfg(feature = "std")]
1010
use std::error::Error;
1111

12+
use core::borrow::Borrow;
1213
use core::cmp::Ordering;
1314
use core::convert::TryFrom;
1415
use core::fmt;
@@ -915,6 +916,20 @@ impl<T: Float> AsRef<T> for NotNan<T> {
915916
}
916917
}
917918

919+
impl Borrow<f32> for NotNan<f32> {
920+
#[inline]
921+
fn borrow(&self) -> &f32 {
922+
&self.0
923+
}
924+
}
925+
926+
impl Borrow<f64> for NotNan<f64> {
927+
#[inline]
928+
fn borrow(&self) -> &f64 {
929+
&self.0
930+
}
931+
}
932+
918933
#[allow(clippy::derive_ord_xor_partial_ord)]
919934
impl<T: Float> Ord for NotNan<T> {
920935
fn cmp(&self, other: &NotNan<T>) -> Ordering {

0 commit comments

Comments
 (0)