Struct version_compare::version_compare::VersionCompare
[−]
[src]
pub struct VersionCompare {}
The main library structure, which provides various static methods for easy version comparison.
This structure uses static methods only, and doesn't need to be constructed.
Methods
impl VersionCompare
[src]
fn compare(a: &str, b: &str) -> Result<CompOp, ()>
Compare two version number strings to each other.
This compares version a
to version b
, and returns whether version a
is greater, less
or equal to version b
.
The two given version numbers must be valid, or an error will be returned.
One of the following ok results may be returned:
CompOp::Eq
CompOp::Lt
CompOp::Gt
Examples
use version_compare::{CompOp, VersionCompare}; // Compare version numbers assert_eq!(VersionCompare::compare("1.2.3", "1.2.3"), Ok(CompOp::Eq)); assert_eq!(VersionCompare::compare("1.2.3", "1.2.4"), Ok(CompOp::Lt)); assert_eq!(VersionCompare::compare("1", "0.1"), Ok(CompOp::Gt));
fn compare_to(a: &str, b: &str, operator: &CompOp) -> Result<bool, ()>
Compare two version number strings to each other and check whether the given comparison
operator
is valid.
The two given version numbers must be valid, or an error will be returned.
Examples
use version_compare::{CompOp, VersionCompare}; // Compare version numbers assert!(VersionCompare::compare_to("1.2.3", "1.2.3", &CompOp::Eq).unwrap()); assert!(VersionCompare::compare_to("1.2.3", "1.2.3", &CompOp::Le).unwrap()); assert!(VersionCompare::compare_to("1.2.3", "1.2.4", &CompOp::Lt).unwrap()); assert!(VersionCompare::compare_to("1", "0.1", &CompOp::Gt).unwrap()); assert!(VersionCompare::compare_to("1", "0.1", &CompOp::Ge).unwrap());