Struct version_compare::version_compare::VersionCompare[][src]

pub struct VersionCompare {}
Expand description

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.

Implementations

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));

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());

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.