#[repr(transparent)]pub struct Reverse<T>(pub T);
Expand description
用于逆序排序的辅助结构体。
该结构是一个帮助器,可与 Vec::sort_by_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]);
RunTuple Fields§
§0: T
Trait Implementations§
source§impl<T> PartialOrd<Reverse<T>> for Reverse<T>where
T: PartialOrd<T>,
impl<T> PartialOrd<Reverse<T>> for Reverse<T>where T: PartialOrd<T>,
impl<T> Copy for Reverse<T>where T: Copy,
impl<T> Eq for Reverse<T>where T: Eq,
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
从拥有的值中借用。 Read more