Skip to content

Instantly share code, notes, and snippets.

@Ophirr33
Created August 19, 2017 01:23
Show Gist options
  • Save Ophirr33/a977d6586717948ed59d44e2234f299e to your computer and use it in GitHub Desktop.
Save Ophirr33/a977d6586717948ed59d44e2234f299e to your computer and use it in GitHub Desktop.
rfc 2033 example
let mut v = [-5i32, 4, 1, -3, 2];
v.sort_unstable();
assert!(v == [-5, -3, 1, 2, 4]);
v.sort_unstable_by(|a, b| b.cmp(a));
assert!(v == [4, 2, 1, -3, -5]);
v.sort_unstable_by_key(|k| k.abs());
assert!(v == [1, 2, -3, 4, -5]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment