#sorting #order #human #natural

human-sort

Human sort (natural sort) implementation

16 releases

0.2.2 Apr 14, 2019
0.2.1 Feb 5, 2019
0.1.14 Jan 28, 2019

#860 in Algorithms

Download history 3018/week @ 2024-07-24 2342/week @ 2024-07-31 3667/week @ 2024-08-07 3600/week @ 2024-08-14 2572/week @ 2024-08-21 2469/week @ 2024-08-28 2476/week @ 2024-09-04 2110/week @ 2024-09-11 2011/week @ 2024-09-18 2840/week @ 2024-09-25 2774/week @ 2024-10-02 3199/week @ 2024-10-09 2658/week @ 2024-10-16 2597/week @ 2024-10-23 2777/week @ 2024-10-30 2115/week @ 2024-11-06

10,613 downloads per month
Used in 30 crates (14 directly)

MIT license

6KB
61 lines

Crates.io Build Status

human-sort

Utilities to sort and compare strings with numeric symbols in human-friendly order.

It built over iterators and compare string slices char by char (except for numerals) until the first difference found without creating Strings or another structures with whole data from provided &str, so doesn't require lots of memory.

Examples

use human_sort::sort;

let mut arr = ["file10.txt", "file2.txt", "file1.txt"];
sort(&mut arr);

assert_eq!(arr, ["file1.txt", "file2.txt", "file10.txt"]);
use std::cmp::Ordering;
use human_sort::compare;

assert_eq!(compare("item200", "item3"), Ordering::Greater);

License

Licensed under MIT license.


lib.rs:

Utilities to sort and compare strings with numeric symbols in human-friendly order.

It built over iterators and compare string slices char by char (except for numerals) until the first difference found without creating Strings or another structures with whole data from provided &str, so doesn't require lots of memory.

Examples

use human_sort::sort;

let mut arr = ["file10.txt", "file2.txt", "file1.txt"];
sort(&mut arr);

assert_eq!(arr, ["file1.txt", "file2.txt", "file10.txt"]);
use std::cmp::Ordering;
use human_sort::compare;

assert_eq!(compare("item200", "item3"), Ordering::Greater);

No runtime deps