[−][src]Function cycle_sort::cycle_sort_by_key
pub fn cycle_sort_by_key<T, F, U>(slice: &mut [T], key: &F) -> usize where
F: Fn(&T) -> U,
U: Ord,
Sorts a slice with a key extraction function and returns the number of writes made.
Examples
// sort by length let mut a = ["zwölf", "zzxjoanw", "zymbel"]; let w = cycle_sort_by_key(&mut a, &|s| s.len()); assert_eq!(a, ["zwölf", "zymbel", "zzxjoanw"]); assert_eq!(w, 2);