Guest User

Untitled

a guest
Jan 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. use std::cmp::Reverse;
  2.  
  3. #[derive(PartialEq)]
  4. struct Thing {
  5. name: String,
  6. score: u8,
  7. }
  8.  
  9. impl Thing {
  10. fn new(name: String, score: u8) -> Self {
  11. Thing { name, score }
  12. }
  13. }
  14.  
  15. fn main() {
  16. let names = vec!["e", "d", "c", "b", "a"];
  17. let scores = vec![4, 5, 5, 3, 7];
  18.  
  19. let mut things = names
  20. .into_iter()
  21. .zip(scores.into_iter())
  22. .map(|(n, s)| Thing::new(n.to_owned(), s))
  23. .collect::<Vec<_>>();
  24.  
  25. things.sort_by_key(|ref thing| (thing.name, Reverse(thing.score)))
  26. }
Add Comment
Please, Sign In to add comment