Crates.io | natural-sort-rs |
lib.rs | natural-sort-rs |
version | 0.1.1 |
source | src |
created_at | 2024-10-04 16:18:58.730781 |
updated_at | 2024-10-04 16:30:15.796546 |
description | sorting strings based on [Natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order) |
homepage | |
repository | https://github.com/Vrtgs/natural-sort-rs |
max_upload_size | |
id | 1396751 |
size | 11,761 |
A #![no_std]
implementation of natural sort order
use natural_sort_rs::{Natural, NaturalSort};
fn main() {
let mut files = ["file2.txt", "file11.txt", "file1.txt"];
files.sort();
assert_eq!(files, ["file1.txt", "file11.txt", "file2.txt"]);
assert!(Natural::str("file0002.txt") > Natural::str("file1B.txt"));
assert!(Natural::str("file0002.txt") < Natural::str("file11.txt"));
let mut files = [
"file1.txt",
"file1B.txt",
"file00.txt",
"file11.txt",
"file0002.txt",
];
files.natural_sort::<str>();
// Here, "file11.txt" comes last because `natural_sort` saw that there was a
// number inside the string, and did a numerical, rather than lexical,
// comparison.
assert_eq!(
files,
[
"file00.txt",
"file1.txt",
"file1B.txt",
"file0002.txt",
"file11.txt"
]
);
}