sortby

Crates.iosortby
lib.rssortby
version0.1.3
sourcesrc
created_at2020-06-17 12:12:09.721544
updated_at2023-05-06 01:37:52.094995
descriptionadds convenient sort functions for Iterators
homepage
repositoryhttps://github.com/sklose/sortby-rs
max_upload_size
id254911
size10,465
Sebastian Klose (sklose)

documentation

README

Rust Crates

Sort By

Convenience functions that allow for sorting iterators.

Example

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);
}
Commit count: 9

cargo fmt