Function quickersort::sort_by_key [] [src]

pub fn sort_by_key<T, K: Ord, F: Fn(&T) -> K>(v: &mut [T], key: F)

Sort using a conversion function.

Example

#[derive(Debug, Eq, PartialEq)]
struct Selector {
    specificity: u32,
    source_order: u32,
}
let mut selectors_scrambled = [
    Selector{ specificity: 1, source_order: 5 },
    Selector{ specificity: 1, source_order: 4 },
    Selector{ specificity: 3, source_order: 1 },
];
let selectors_sorted = [
    Selector{ specificity: 1, source_order: 4 },
    Selector{ specificity: 1, source_order: 5 },
    Selector{ specificity: 3, source_order: 1 },
];
::quickersort::sort_by_key(
    &mut selectors_scrambled,
    |a| (a.specificity, a.source_order)
);
assert_eq!(selectors_scrambled, selectors_sorted);