Document That FloatOrd Implements Hash and Eq Too (#5228)

# Objective

- Slight documentation tweak to make it more clear that `FloatOrd` also implements `Hash` and `Eq`, not just `Ord`.
- I know that it does show that Hash is implemented in the docs, but I had missed it after reading the description and assuming it didn't do it, so hopefully this helps other people who might miss it like I did. :)

## Solution

- Just mention in the Hash and Eq implementation in the docstring.
This commit is contained in:
Zicklag 2022-07-11 14:11:27 +00:00
parent 9b6253b769
commit 81bb4ef300

View file

@ -4,9 +4,15 @@ use std::{
ops::Neg, ops::Neg,
}; };
/// A wrapper type that enables ordering floats. This is a work around for the famous "rust float /// A wrapper for floats that implements [`Ord`], [`Eq`], and [`Hash`] traits.
/// ordering" problem. By using it, you acknowledge that sorting NaN is undefined according to spec. ///
/// This implementation treats NaN as the "smallest" float. /// This is a work around for the fact that the IEEE 754-2008 standard,
/// implemented by Rust's [`f32`] type,
/// doesn't define an ordering for [`NaN`](f32::NAN),
/// and `NaN` is not considered equal to any other `NaN`.
///
/// Wrapping a float with `FloatOrd` breaks conformance with the standard
/// by sorting `NaN` as less than all other numbers and equal to any other `NaN`.
#[derive(Debug, Copy, Clone, PartialOrd)] #[derive(Debug, Copy, Clone, PartialOrd)]
pub struct FloatOrd(pub f32); pub struct FloatOrd(pub f32);