Alphanumeric Sort
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 = ;
names.sort;
assert_eq!;
Thus, in this kind of case, an alphanumeric sort might come in handy.
extern crate alphanumeric_sort;
let mut names = ;
sort_str_slice;
assert_eq!;
extern crate alphanumeric_sort;
use Path;
let mut paths = ;
sort_path_slice;
assert_eq!;
About the compare_*
Functions and the sort_*
Functions
To sort a slice, the code can also be written like,
extern crate alphanumeric_sort;
use Path;
let mut paths = ;
paths.sort_by;
assert_eq!;
But it is not recommended because the compare_*
functions try to convert data (e.g Path
, CStr
) to &str
every time in its execution and thus they are slower than the sort_*
functions when sorting a slice.
No Std
Disable the default features to compile this crate without std.
[]
= "*"
= false
Benchmark
Crates.io
https://crates.io/crates/alphanumeric-sort
Documentation
https://docs.rs/alphanumeric-sort