#sorting #version #gnu #algorithm

vsort

GNU Version Sort Rust implementation

2 unstable releases

0.2.0 Aug 4, 2023
0.1.0 Jun 30, 2023

#1308 in Algorithms

Download history 556/week @ 2024-07-27 417/week @ 2024-08-03 496/week @ 2024-08-10 1137/week @ 2024-08-17 770/week @ 2024-08-24 508/week @ 2024-08-31 503/week @ 2024-09-07 520/week @ 2024-09-14 569/week @ 2024-09-21 635/week @ 2024-09-28 451/week @ 2024-10-05 664/week @ 2024-10-12 624/week @ 2024-10-19 409/week @ 2024-10-26 544/week @ 2024-11-02 555/week @ 2024-11-09

2,203 downloads per month
Used in lsd

MIT license

22KB
385 lines

TESTS License: MIT Latest version

vsort

A Rust library that implements the GNU version sort algorithm. It follows the spec given here.

Installation

cargo add vsort

Why vsort?

Other version sort implementations don't match the GNU spec, and some were missing tests. The goal is to match the behavior of the core utils implementation as close as possible. If you notice any discrepancies please open an issue.

Why not FFI?

FFI is probably your best bet if you need absolute parity with GNU version sort. In the case you want their algorithm in Rust here it is :)

Usage:

use vsort::{compare, sort};

fn main() {
    let mut file_names = vec![
        "a.txt",
        "b 1.txt",
        "b 10.txt",
        "b 11.txt",
        "b 5.txt",
        "Ssm.txt",
    ];

    // Pass to sort_by
    file_names.sort_by(|a, b| compare(a, b));
    assert_eq!(
        file_names,
        vec!["Ssm.txt", "a.txt", "b 1.txt", "b 5.txt", "b 10.txt", "b 11.txt"]
    );

    let mut file_names = vec![
        "a.txt",
        "b 1.txt",
        "b 10.txt",
        "b 11.txt",
        "b 5.txt",
        "Ssm.txt",
    ];
    // Alternatively
    sort(&mut file_names);
    assert_eq!(
        file_names,
        vec!["Ssm.txt", "a.txt", "b 1.txt", "b 5.txt", "b 10.txt", "b 11.txt"]
    );
}

No runtime deps