Skip to content

Commit

Permalink
Implement Borrow for NotNan
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mbrubeck committed Sep 7, 2021
1 parent 5cf18fe commit bfabcc9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern crate std;
#[cfg(feature = "std")]
use std::error::Error;

use core::borrow::Borrow;
use core::cmp::Ordering;
use core::convert::TryFrom;
use core::fmt;
Expand Down Expand Up @@ -915,6 +916,20 @@ impl<T: Float> AsRef<T> for NotNan<T> {
}
}

impl Borrow<f32> for NotNan<f32> {
#[inline]
fn borrow(&self) -> &f32 {
&self.0
}
}

impl Borrow<f64> for NotNan<f64> {
#[inline]
fn borrow(&self) -> &f64 {
&self.0
}
}

#[allow(clippy::derive_ord_xor_partial_ord)]
impl<T: Float> Ord for NotNan<T> {
fn cmp(&self, other: &NotNan<T>) -> Ordering {
Expand Down

0 comments on commit bfabcc9

Please sign in to comment.