Struct core::cmp::Reverse1.19.0[][src]

#[repr(transparent)]
pub struct Reverse<T>(pub T);
Expand description

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]);
Run

Trait Implementations

impl<T: Clone> Clone for Reverse<T>[src]

fn clone(&self) -> Reverse<T>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, other: &Self)[src]

Performs copy-assignment from source. Read more

impl<T: Debug> Debug for Reverse<T>[src]

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

Formats the value using the given formatter. Read more

impl<T: Default> Default for Reverse<T>[src]

fn default() -> Reverse<T>[src]

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

impl<T: Hash> Hash for Reverse<T>[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

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

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

impl<T: Ord> Ord for Reverse<T>[src]

fn cmp(&self, other: &Reverse<T>) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self where
    Self: Sized
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self where
    Self: Sized
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self where
    Self: Sized
1.50.0[src]

Restrict a value to a certain interval. Read more

impl<T: PartialEq> PartialEq<Reverse<T>> for Reverse<T>[src]

fn eq(&self, other: &Reverse<T>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Reverse<T>) -> bool[src]

This method tests for !=.

impl<T: PartialOrd> PartialOrd<Reverse<T>> for Reverse<T>[src]

fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering>[src]

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

fn lt(&self, other: &Self) -> bool[src]

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

fn le(&self, other: &Self) -> bool[src]

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

fn gt(&self, other: &Self) -> bool[src]

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

fn ge(&self, other: &Self) -> bool[src]

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

impl<T: Copy> Copy for Reverse<T>[src]

impl<T: Eq> Eq for Reverse<T>[src]

impl<T> StructuralEq for Reverse<T>[src]

impl<T> StructuralPartialEq for Reverse<T>[src]

Auto Trait Implementations

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&Self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&Self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut Self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(Self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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>[src]

Performs the conversion.