https://github.com/sklose/sortby-rs
Adds sorting for Iterators
https://github.com/sklose/sortby-rs
algorithms iterators
Last synced: 6 months ago
JSON representation
Adds sorting for Iterators
- Host: GitHub
- URL: https://github.com/sklose/sortby-rs
- Owner: sklose
- License: mit
- Created: 2020-06-17T11:56:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-18T15:00:04.000Z (over 2 years ago)
- Last Synced: 2025-04-12T04:40:57.401Z (6 months ago)
- Topics: algorithms, iterators
- Language: Rust
- Homepage:
- Size: 8.79 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/sklose/sortby-rs/actions/workflows/ci.yml)
[](https://crates.io/crates/sortby)
[](https://docs.rs/sortby)# Sort By
Convenience functions that allow for sorting iterators.
# Example
```rust
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);
}
```