Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::cmp::Reverse;
- #[derive(PartialEq)]
- struct Thing {
- name: String,
- score: u8,
- }
- impl Thing {
- fn new(name: String, score: u8) -> Self {
- Thing { name, score }
- }
- }
- fn main() {
- let names = vec!["e", "d", "c", "b", "a"];
- let scores = vec![4, 5, 5, 3, 7];
- let mut things = names
- .into_iter()
- .zip(scores.into_iter())
- .map(|(n, s)| Thing::new(n.to_owned(), s))
- .collect::<Vec<_>>();
- things.sort_by_key(|ref thing| (thing.name, Reverse(thing.score)))
- }
Add Comment
Please, Sign In to add comment