natural-sort-rs 0.2.1

sorting strings based on [Natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order)
Documentation
  • Coverage
  • 11.76%
    2 out of 17 items documented1 out of 16 items with examples
  • Size
  • Source code size: 11.66 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.7 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Vrtgs/natural-sort-rs
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Vrtgs

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