daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 54 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. 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. }
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