4 releases

0.1.3 May 6, 2023
0.1.2 Jul 26, 2020
0.1.1 Jun 18, 2020
0.1.0 Jun 17, 2020

#868 in Algorithms

Download history 204/week @ 2023-12-30 163/week @ 2024-01-06 324/week @ 2024-01-13 214/week @ 2024-01-20 159/week @ 2024-01-27 149/week @ 2024-02-03 216/week @ 2024-02-10 265/week @ 2024-02-17 244/week @ 2024-02-24 400/week @ 2024-03-02 495/week @ 2024-03-09 249/week @ 2024-03-16 260/week @ 2024-03-23 224/week @ 2024-03-30 292/week @ 2024-04-06 216/week @ 2024-04-13

1,037 downloads per month

MIT license

10KB
203 lines

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);
}

lib.rs:

This crate adds convenient sort functions for Iterators.

Example

use sortby::*;

#[derive(Clone, Debug, Eq, PartialEq)]
struct Person {
  pub age: i32,
  pub name: &'static str,
}

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);

No runtime deps