#sort #path #file #number #alphanumeric

alphanumeric-sort

This crate can help you sort order for files and folders whose names contain numerals

14 stable releases

✓ Uses Rust 2018 edition

1.0.13 May 21, 2020
1.0.12 Feb 20, 2020
1.0.11 Sep 16, 2019
1.0.7 Jul 28, 2019
1.0.3 Aug 29, 2018

#17 in Algorithms

Download history 134/week @ 2020-02-06 147/week @ 2020-02-13 392/week @ 2020-02-20 440/week @ 2020-02-27 597/week @ 2020-03-05 392/week @ 2020-03-12 443/week @ 2020-03-19 424/week @ 2020-03-26 428/week @ 2020-04-02 317/week @ 2020-04-09 466/week @ 2020-04-16 562/week @ 2020-04-23 768/week @ 2020-04-30 657/week @ 2020-05-07 593/week @ 2020-05-14 652/week @ 2020-05-21

2,139 downloads per month
Used in less than 7 crates

MIT license

9KB
151 lines

Alphanumeric Sort

Build Status

This crate can help you sort order for files and folders whose names contain numerals.

Motives and Examples

With the Rust native sort method, strings and paths are arranged into lexicographical order. In some cases, it is not so intuitive. For example, there are screen snap shots named by shot-%N like shot-2, shot-1, shot-11. After a lexicographical sorting, they will be ordered into shot-1, shot-11, shot-2. However, we would prefer shot-1, shot-2, shot-11 mostly.

let mut names = ["shot-2", "shot-1", "shot-11"];

names.sort();

assert_eq!(["shot-1", "shot-11", "shot-2"], names);

Thus, in this kind of case, an alphanumeric sort might come in handy.

extern crate alphanumeric_sort;

let mut names = ["shot-2", "shot-1", "shot-11"];

alphanumeric_sort::sort_str_slice(&mut names);

assert_eq!(["shot-1", "shot-2", "shot-11"], names);
extern crate alphanumeric_sort;

use std::path::Path;

let mut paths = [Path::new("shot-2"), Path::new("shot-1"), Path::new("shot-11")];

alphanumeric_sort::sort_path_slice(&mut paths);

assert_eq!([Path::new("shot-1"), Path::new("shot-2"), Path::new("shot-11")], paths);

Crates.io

https://crates.io/crates/alphanumeric-sort

Documentation

https://docs.rs/alphanumeric-sort

License

MIT

No runtime deps