[][src]Macro colmac::sort

macro_rules! sort {
    ( $collection:expr ) => { ... };
    ( $collection:expr, $compare_fn:expr ) => { ... };
}

Sorts the input collection that impl's the trait std::ops::IndexMut.

There are two ways to invoke this macro:

  1. with one argument, a mutable collection
    1. uses slice::sort_unstable to sort
  2. with two arguments, a mutable collection followed by a closure
    1. passes the closure to slice::sort_unstable_by to sort

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