[][src]Enum version_compare::comp_op::CompOp

pub enum CompOp {
    Eq,
    Ne,
    Lt,
    Le,
    Ge,
    Gt,
}

Enum of supported comparison operators.

Variants

Eq

Equal (==, =). When version A is equal to B.

Ne

Not equal (!=, !, <>). When version A is not equal to B.

Lt

Less than (<). When version A is less than B but not equal.

Le

Less or equal (<=). When version A is less than or equal to B.

Ge

Greater or equal (>=). When version A is greater than or equal to B.

Gt

Greater than (>). When version A is greater than B but not equal.

Methods

impl CompOp[src]

pub fn from_sign(sign: &str) -> Result<CompOp, ()>[src]

Get a comparison operator by it's sign. Whitespaces are stripped from the sign string. An error is returned if the sign isn't recognized.

The following signs are supported:

  • == or = -> Eq
  • != or ! or <> -> Ne
  • < -> Lt
  • <= -> Le
  • >= -> Ge
  • > -> Gt

Examples

use version_compare::CompOp;

assert_eq!(CompOp::from_sign("=="), Ok(CompOp::Eq));
assert_eq!(CompOp::from_sign("<"), Ok(CompOp::Lt));
assert_eq!(CompOp::from_sign("  >=   "), Ok(CompOp::Ge));
assert!(CompOp::from_sign("*").is_err());

pub fn from_name(sign: &str) -> Result<CompOp, ()>[src]

Get a comparison operator by it's name. Names are case-insensitive, and whitespaces are stripped from the string. An error is returned if the name isn't recognized.

Examples

use version_compare::CompOp;

assert_eq!(CompOp::from_name("eq"), Ok(CompOp::Eq));
assert_eq!(CompOp::from_name("lt"), Ok(CompOp::Lt));
assert_eq!(CompOp::from_name("  Ge   "), Ok(CompOp::Ge));
assert!(CompOp::from_name("abc").is_err());

pub fn from_ord(ord: Ordering) -> CompOp[src]

Get the comparison operator from Rusts Ordering enum.

The following comparison operators are returned:

  • Ordering::Less -> Lt
  • Ordering::Equal -> Eq
  • Ordering::Greater -> Gt

pub fn name(&self) -> &str[src]

Get the name of this comparison operator.

Examples

use version_compare::CompOp;

assert_eq!(CompOp::Eq.name(), "eq");
assert_eq!(CompOp::Lt.name(), "lt");
assert_eq!(CompOp::Ge.name(), "ge");

pub fn as_inverted(self) -> Self[src]

Covert to the inverted comparison operator.

This uses the following bidirectional rules:

  • Eq <-> Ne
  • Lt <-> Ge
  • Le <-> Gt

Examples

use version_compare::CompOp;

assert_eq!(CompOp::Eq.as_inverted(), CompOp::Ne);
assert_eq!(CompOp::Lt.as_inverted(), CompOp::Ge);
assert_eq!(CompOp::Gt.as_inverted(), CompOp::Le);

pub fn invert(&self) -> Self[src]

Get the inverted comparison operator.

This uses the following bidirectional rules:

  • Eq <-> Ne
  • Lt <-> Ge
  • Le <-> Gt

Examples

use version_compare::CompOp;

assert_eq!(CompOp::Eq.invert(), CompOp::Ne);
assert_eq!(CompOp::Lt.invert(), CompOp::Ge);
assert_eq!(CompOp::Gt.invert(), CompOp::Le);

pub fn as_opposite(self) -> Self[src]

Convert to the opposite comparison operator.

This uses the following bidirectional rules:

  • Eq <-> Ne
  • Lt <-> Gt
  • Le <-> Ge

Examples

use version_compare::CompOp;

assert_eq!(CompOp::Eq.as_opposite(), CompOp::Ne);
assert_eq!(CompOp::Lt.as_opposite(), CompOp::Gt);
assert_eq!(CompOp::Ge.as_opposite(), CompOp::Le);

pub fn opposite(&self) -> Self[src]

Get the opposite comparison operator.

This uses the following bidirectional rules:

  • Eq <-> Ne
  • Lt <-> Gt
  • Le <-> Ge

Examples

use version_compare::CompOp;

assert_eq!(CompOp::Eq.opposite(), CompOp::Ne);
assert_eq!(CompOp::Lt.opposite(), CompOp::Gt);
assert_eq!(CompOp::Ge.opposite(), CompOp::Le);

pub fn as_flipped(self) -> Self[src]

Convert to the flipped comparison operator.

This uses the following bidirectional rules:

  • Lt <-> Gt
  • Le <-> Ge
  • Other operators are returned as is.

Examples

use version_compare::CompOp;

assert_eq!(CompOp::Eq.as_flipped(), CompOp::Eq);
assert_eq!(CompOp::Lt.as_flipped(), CompOp::Gt);
assert_eq!(CompOp::Ge.as_flipped(), CompOp::Le);

pub fn flip(&self) -> Self[src]

Get the flipped comparison operator.

This uses the following bidirectional rules:

  • Lt <-> Gt
  • Le <-> Ge
  • Other operators are returned as is.

Examples

use version_compare::CompOp;

assert_eq!(CompOp::Eq.flip(), CompOp::Eq);
assert_eq!(CompOp::Lt.flip(), CompOp::Gt);
assert_eq!(CompOp::Ge.flip(), CompOp::Le);

pub fn sign(&self) -> &'static str[src]

Get the sign for this comparison operator.

The following signs are returned:

  • Eq -> ==
  • Ne -> !=
  • Lt -> <
  • Le -> <=
  • Ge -> >=
  • Gt -> >

Note: Some comparison operators also support other signs, such as = for Eq and ! for Ne, these are never returned by this method however as the table above is used.

Examples

use version_compare::CompOp;

assert_eq!(CompOp::Eq.sign(), "==");
assert_eq!(CompOp::Lt.sign(), "<");
assert_eq!(CompOp::Ge.flip().sign(), "<=");

pub fn factor(&self) -> i8[src]

Get a factor (number) for this comparison operator. These factors can be useful for quick calculations.

The following factor numbers are returned:

  • Eq or Ne -> 0
  • Lt or Le -> -1
  • Gt or Ge -> 1

Examples

use version_compare::Version;

let ver_a = Version::from("1.2.3").unwrap();
let ver_b = Version::from("1.3").unwrap();

assert_eq!(ver_a.compare(&ver_b).factor(), -1);
assert_eq!(10 * ver_b.compare(&ver_a).factor(), 10);

pub fn ord(&self) -> Option<Ordering>[src]

Get Rust's ordering for this comparison operator.

The following comparison operators are supported:

  • Eq -> Ordering::Equal
  • Lt -> Ordering::Less
  • Gt -> Ordering::Greater

For other comparison operators None is returned.

Examples

use std::cmp::Ordering;
use version_compare::Version;

let ver_a = Version::from("1.2.3").unwrap();
let ver_b = Version::from("1.3").unwrap();

assert_eq!(ver_a.compare(&ver_b).ord().unwrap(), Ordering::Less);

Trait Implementations

impl Clone for CompOp[src]

impl PartialEq<CompOp> for CompOp[src]

impl Debug for CompOp[src]

Auto Trait Implementations

impl Send for CompOp

impl Unpin for CompOp

impl Sync for CompOp

impl UnwindSafe for CompOp

impl RefUnwindSafe for CompOp

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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]