macro_rules! sort {
( $collection:expr ) => { ... };
( $collection:expr, $compare_fn:expr ) => { ... };
}Expand description
Sorts the input collection that impl’s the trait std::ops::IndexMut.
There are two ways to invoke this macro:
- with one argument, a mutable collection
- uses
slice::sort_unstableto sort
- uses
- with two arguments, a mutable collection followed by a closure
- passes the closure to
slice::sort_unstable_byto sort
- passes the closure to
§Examples
#[macro_use] extern crate colmac;
use std::cmp::Ordering::{Equal, Greater, Less};
// sort without a custom closure
let mut v1 = vec![2, 4, -1];
sort!(v1);
assert_eq!(vec![-1, 2, 4], v1);
// sort with; sort in reverse order
let mut v2 = vec![2, 4, -1];
sort!(v2, |a, b| match a.cmp(b) {
Less => Greater,
Greater => Less,
Equal => Equal,
});
assert_eq!(vec![4, 2, -1], v2);