uapi-version 0.4.0

Compare versions according to the UAPI Version Format Specification
Documentation
  • Coverage
  • 60%
    3 out of 5 items documented3 out of 5 items with examples
  • Size
  • Source code size: 23.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.18 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • nikstur/uapi-version
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nikstur

uapi-version

Compare versions according to the UAPI Version Format Specification.

This library is written purely in Rust and does not rely on any third party dependencies. It is #![no_std] and can thus, for example, also be used for UEFI development.

Uses the same test suite that systemd uses to test their strverscmp_improved() function.

Any deviation from the UAPI specification is a bug. Please report it if you find one!

Usage

Add uapi-version to your Cargo.toml:

cargo add uapi-version

You can compare two versions:

use std::cmp::Ordering;

use uapi_version::Version;

fn main() {
    let a = Version::from("225.1");
    let b = Version::from("2");
    assert_eq!(a.cmp(&b), Ordering::Greater)
}

You can sort a list of versions:

use uapi_version::Version;

fn main() {
    let mut versions = [
        "5.2",
        "abc-5",
        "1.0.0~rc1",
    ].map(Version::from);

    versions.sort();

    assert_eq!(versions, [ "abc-5", "1.0.0~rc1", "5.2" ].map(Version::from))
}

You can also compare version strings directly:

use std::cmp::Ordering;

use uapi_version::strverscmp;

fn main() {
    assert_eq!(strverscmp("124", "123"), Ordering::Greater)
}