natural-sort-rs

Crates.ionatural-sort-rs
lib.rsnatural-sort-rs
version0.1.1
sourcesrc
created_at2024-10-04 16:18:58.730781
updated_at2024-10-04 16:30:15.796546
descriptionsorting strings based on [Natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order)
homepage
repositoryhttps://github.com/Vrtgs/natural-sort-rs
max_upload_size
id1396751
size11,761
Vrtgs (Vrtgs)

documentation

README

Crates.io docs.rs

A #![no_std] implementation of natural sort order

Example

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"
        ]
    );
}
Commit count: 7

cargo fmt