Guest User

Untitled

a guest
Jan 20th, 2019
77
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. fn main() {
  15. let names = vec!["e", "d", "c", "b", "a"];
  16. let scores = vec![4, 5, 5, 3, 7];
  17.  
  18. let mut things = names
  19. .into_iter()
  20. .zip(scores.into_iter())
  21. .map(|(n, s)| Thing::new(n.to_owned(), s))
  22. .collect::<Vec<_>>();
  23.  
  24. things.sort_by_key(|ref thing| (thing.name, Reverse(thing.score)))
  25. }
Add Comment
Please, Sign In to add comment