Function version_compare::compare[][src]

pub fn compare<A, B>(a: A, b: B) -> Result<Cmp, ()> where
    A: AsRef<str>,
    B: AsRef<str>, 
Expand description

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:

  • Cmp::Eq
  • Cmp::Lt
  • Cmp::Gt

Examples

use version_compare::{Cmp, compare};

// Compare version numbers
assert_eq!(compare("1.2.3", "1.2.3"), Ok(Cmp::Eq));
assert_eq!(compare("1.2.3", "1.2.4"), Ok(Cmp::Lt));
assert_eq!(compare("1", "0.1"), Ok(Cmp::Gt));