#[repr(transparent)]
pub struct OrderedFloat<T: Float>(pub T);
Expand description

A wrapper around Floats providing an implementation of Ord and Hash.

NaN is sorted as greater than all other values and equal to itself, in contradiction with the IEEE standard.

Tuple Fields§

§0: T

Implementations§

source§

impl<T: Float> OrderedFloat<T>

source

pub fn into_inner(self) -> T

Get the value out.

Trait Implementations§

source§

impl<T: Float> Add for OrderedFloat<T>

§

type Output = OrderedFloat<T>

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
source§

impl<T: Float> AsMut<T> for OrderedFloat<T>

source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T: Float> AsRef<T> for OrderedFloat<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: Float> Bounded for OrderedFloat<T>

source§

fn min_value() -> Self

Returns the smallest finite number this type can represent
source§

fn max_value() -> Self

Returns the largest finite number this type can represent
source§

impl<T: Clone + Float> Clone for OrderedFloat<T>

source§

fn clone(&self) -> OrderedFloat<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Float> Debug for OrderedFloat<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default + Float> Default for OrderedFloat<T>

source§

fn default() -> OrderedFloat<T>

Returns the “default value” for a type. Read more
source§

impl<T: Float> Deref for OrderedFloat<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T: Float> DerefMut for OrderedFloat<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<T: Float + Display> Display for OrderedFloat<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Float> Div for OrderedFloat<T>

§

type Output = OrderedFloat<T>

The resulting type after applying the / operator.
source§

fn div(self, other: Self) -> Self

Performs the / operation. Read more
source§

impl<T: Float> From<T> for OrderedFloat<T>

source§

fn from(val: T) -> Self

Converts to this type from the input type.
source§

impl<T: Float + FromStr> FromStr for OrderedFloat<T>

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Convert a &str to OrderedFloat. Returns an error if the string fails to parse.

use ordered_float::OrderedFloat;

assert!("-10".parse::<OrderedFloat<f32>>().is_ok());
assert!("abc".parse::<OrderedFloat<f32>>().is_err());
assert!("NaN".parse::<OrderedFloat<f32>>().is_ok());
§

type Err = <T as FromStr>::Err

The associated error which can be returned from parsing.
source§

impl<T: Float> Hash for OrderedFloat<T>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Into<f32> for OrderedFloat<f32>

source§

fn into(self) -> f32

Converts this type into the (usually inferred) input type.
source§

impl Into<f64> for OrderedFloat<f64>

source§

fn into(self) -> f64

Converts this type into the (usually inferred) input type.
source§

impl<T: Float> Mul for OrderedFloat<T>

§

type Output = OrderedFloat<T>

The resulting type after applying the * operator.
source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
source§

impl<T: Float> Neg for OrderedFloat<T>

§

type Output = OrderedFloat<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl<T: Float> Ord for OrderedFloat<T>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T: Float> PartialEq for OrderedFloat<T>

source§

fn eq(&self, other: &OrderedFloat<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Float> PartialOrd for OrderedFloat<T>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Float> Sub for OrderedFloat<T>

§

type Output = OrderedFloat<T>

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
source§

impl<T: Float> Zero for OrderedFloat<T>

source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

impl<T: Copy + Float> Copy for OrderedFloat<T>

source§

impl<T: Float> Eq for OrderedFloat<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for OrderedFloat<T>
where T: RefUnwindSafe,

§

impl<T> Send for OrderedFloat<T>
where T: Send,

§

impl<T> Sync for OrderedFloat<T>
where T: Sync,

§

impl<T> Unpin for OrderedFloat<T>
where T: Unpin,

§

impl<T> UnwindSafe for OrderedFloat<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> LowerBounded for T
where T: Bounded,

source§

fn min_value() -> T

Returns the smallest finite number this type can represent
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UpperBounded for T
where T: Bounded,

source§

fn max_value() -> T

Returns the largest finite number this type can represent