Module feature_check::version

source ·
Expand description

Parse version strings and compare them.

The Version struct may be used to break a version string down into its separate components and then compare it to another one, e.g. to decide whether a certain feature is really supported.

use std::cmp;

use feature_check::version::Version;

let v1: Version = "2.1".parse()?;
let v2: Version = "2.2.b2".parse()?;
println!("{v1} {res:?} {v2}", res = v1.cmp(&v2));
println!("equal? {res}", res = v1 == v2);
println!("smaller: {res}", res = cmp::min(&v1, &v2));
println!("larger: {res}", res = cmp::max(&v1, &v2));
println!("v1: {v1}");
for comp in &v1 {
    println!(
        "- {num}/{rest}",
        num = match comp.num {
            Some(value) => value.to_string(),
            None => "(none)".to_string(),
        },
        rest = comp.rest,
    );
}
println!("v2: {v2}");
for comp in v2.into_iter() {
    println!(
        "- {num}/{rest}",
        num = match comp.num {
            Some(value) => value.to_string(),
            None => "(none)".to_string(),
        },
        rest = comp.rest,
    );
}

Structs§

  • A version string, both in full and broken down into components.
  • A single version component, e.g. “3” or “b2”.

Enums§

  • An error that occurred while parsing a version string.