Struct std::cmp::Reverse
#[repr(transparent)]pub struct Reverse<T>(pub T);
A helper struct for reverse ordering.
This struct is a helper to be used with functions like Vec::sort_by_key
and can be used to reverse order a part of a key.
Examples
use std::cmp::Reverse; let mut v = vec![1, 2, 3, 4, 5, 6]; v.sort_by_key(|&num| (num > 3, Reverse(num))); assert_eq!(v, vec![3, 2, 1, 6, 5, 4]);
Tuple Fields
0: T
Trait Implementations
pub fn clone(&self) -> Reverse<T>
Returns a copy of the value. Read more
pub fn clone_from(&mut self, other: &Reverse<T>)
Performs copy-assignment from source
. Read more
pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Formats the value using the given formatter. Read more
pub fn cmp(&self, other: &Reverse<T>) -> Ordering
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
Restrict a value to a certain interval. Read more
pub fn eq(&self, other: &Reverse<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
pub fn ne(&self, other: &Reverse<T>) -> bool
This method tests for !=
.
impl<T> PartialOrd<Reverse<T>> for Reverse<T> where
T: PartialOrd<T>,
pub fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
pub fn lt(&self, other: &Reverse<T>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
pub fn le(&self, other: &Reverse<T>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
pub fn gt(&self, other: &Reverse<T>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
pub fn ge(&self, other: &Reverse<T>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T> StructuralEq for Reverse<T>
impl<T> StructuralPartialEq for Reverse<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Reverse<T> where
T: RefUnwindSafe,
impl<T> Send for Reverse<T> where
T: Send,
impl<T> Sync for Reverse<T> where
T: Sync,
impl<T> Unpin for Reverse<T> where
T: Unpin,
impl<T> UnwindSafe for Reverse<T> where
T: UnwindSafe,
Blanket Implementations
impl<T> From<T> for T
pub fn from(t: T) -> T
Performs the conversion.
pub fn into(self) -> U
Performs the conversion.
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
#41263)recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/cmp/struct.Reverse.html