Struct version_compare::version::Version [] [src]

pub struct Version<'a> { /* fields omitted */ }

Version struct. A wrapper for a version number string.

Methods

impl<'a> Version<'a>
[src]

Version struct implementation.

Create a Version instance from a version string.

The version string should be passed to the version parameter.

Examples

use version_compare::comp_op::CompOp;
use version_compare::version::Version;

let ver = Version::from("1.2.3").unwrap();

assert_eq!(ver.compare(&Version::from("1.2.3").unwrap()), CompOp::Eq);

Get the original version string.

Examples

use version_compare::version::Version;

let ver = Version::from("1.2.3").unwrap();

assert_eq!(ver.as_str(), "1.2.3");

Get the number of parts in this version string.

Examples

use version_compare::version::Version;

let ver_a = Version::from("1.2.3").unwrap();
let ver_b = Version::from("1.2.3.4").unwrap();

assert_eq!(ver_a.part_count(), 3);
assert_eq!(ver_b.part_count(), 4);

Compare this version to the given other version.

This method returns one of the following comparison operators: - Lt - Eq - Gt

Examples:

use version_compare::comp_op::CompOp;
use version_compare::version::Version;

assert_eq!(Version::from("1.2").unwrap().compare(&Version::from("1.3.2").unwrap()), CompOp::Lt);
assert_eq!(Version::from("1.9").unwrap().compare(&Version::from("1.9").unwrap()), CompOp::Eq);
assert_eq!(Version::from("0.3.0.0").unwrap().compare(&Version::from("0.3").unwrap()), CompOp::Eq);
assert_eq!(Version::from("2").unwrap().compare(&Version::from("1.7.3").unwrap()), CompOp::Gt);

Compare this version to the given other version, and check whether the given comparison operator is valid.

Examples:

use version_compare::comp_op::CompOp;
use version_compare::version::Version;

assert!(Version::from("1.2").unwrap().compare_to(&Version::from("1.3.2").unwrap(), &CompOp::Lt));
assert!(Version::from("1.2").unwrap().compare_to(&Version::from("1.3.2").unwrap(), &CompOp::Le));
assert!(Version::from("1.2").unwrap().compare_to(&Version::from("1.2").unwrap(), &CompOp::Eq));
assert!(Version::from("1.2").unwrap().compare_to(&Version::from("1.2").unwrap(), &CompOp::Le));