Crates.io | sortby |
lib.rs | sortby |
version | 0.1.3 |
source | src |
created_at | 2020-06-17 12:12:09.721544 |
updated_at | 2023-05-06 01:37:52.094995 |
description | adds convenient sort functions for Iterators |
homepage | |
repository | https://github.com/sklose/sortby-rs |
max_upload_size | |
id | 254911 |
size | 10,465 |
Convenience functions that allow for sorting iterators.
use sortby::*;
#[derive(Clone, Debug, Eq, PartialEq)]
struct Person {
pub age: i32,
pub name: &'static str,
}
fn main() {
let data = vec![
Person {
name: "Rich",
age: 18,
},
Person {
name: "Bob",
age: 9,
},
Person {
name: "Marc",
age: 21,
},
Person {
name: "Alice",
age: 18,
},
];
let sorted: Vec<_> = data.iter()
.sort_by_desc(|p| p.age)
.then_sort_by(|p| p.name)
.collect();
println!("{:#?}", sorted);
}