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.
fn from(version: &'a str) -> Option<Self>
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);
fn as_str(&self) -> &str
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");
fn part_count(&self) -> usize
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);
fn compare(&self, other: &Version) -> CompOp
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);
fn compare_to(&self, other: &Version, operator: &CompOp) -> bool
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));