daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top