Crate uapi_version

Source
Expand description

Compare versions according to the UAPI Version Format Specification.

This implementation is written purely in Rust and does not rely on any third party dependencies. Most notably, it doesn’t link to libsystemd. It is #![no_std] and thus can, for example, also be used for UEFI development.

§Examples

You can compare two versions:

use std::cmp::Ordering;

use uapi_version::Version;

let a = Version::from("225.1");
let b = Version::from("2");

assert_eq!(a.cmp(&b), Ordering::Greater)

Version implements [std::cmp::Ord] and thus can be used to order a list of versions.

use uapi_version::Version;

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 use strverscmp to compare two strings directly:

use std::cmp::Ordering;

use uapi_version::strverscmp;

assert_eq!(strverscmp("124", "123"), Ordering::Greater)

Structs§

Version
The Version type.

Functions§

strverscmp
Compare two version strings.