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

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]

pub fn compare(a: &str, b: &str) -> Result<CompOp, ()>[src]

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

pub fn compare_to(a: &str, b: &str, operator: &CompOp) -> Result<bool, ()>[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]