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.

§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§

Functions§