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

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

Comparison operators.

Variants

Eq

Equal to. (==)

Ne

Not equal to. (!=)

Lt

Less than. (<)

Le

Less than or equal to. (<=)

Ge

Greater than or equal to. (>=)

Gt

Greater than. (>)

Implementations

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:

  • ==: Eq
  • !=: Ne
  • <: Lt
  • <=: Le
  • =: Ge

  • : Gt

Examples
use version_compare::comp_op::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());

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

Get the name of this comparison operator.

Examples
use version_compare::comp_op::CompOp;

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

Covert to the inverted comparison operator.

This uses the following bidirectional rules:

  • Eq <-> Ne
  • Lt <-> Ge
  • Le <-> Gt
Examples
use version_compare::comp_op::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);

Get the inverted comparison operator.

This uses the following bidirectional rules:

  • Eq <-> Ne
  • Lt <-> Ge
  • Le <-> Gt
Examples
use version_compare::comp_op::CompOp;

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

Convert to the opposite comparison operator.

This uses the following bidirectional rules:

  • Eq <-> Ne
  • Lt <-> Gt
  • Le <-> Ge
Examples
use version_compare::comp_op::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);

Get the opposite comparison operator.

This uses the following bidirectional rules:

  • Eq <-> Ne
  • Lt <-> Gt
  • Le <-> Ge
Examples
use version_compare::comp_op::CompOp;

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

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

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::comp_op::CompOp;

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

Get the sign for this comparison operator.

The following signs are returned:

  • Eq: ==
  • Ne: !=
  • Lt: <
  • Le: <=
  • Ge: >=
  • Gt: >
Examples
use version_compare::comp_op::CompOp;

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

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

The following factor numbers are returned:

  • Eq | Ne: 0
  • Lt | Le: -1
  • Gt | Ge: 1
Examples
use version_compare::version::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);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.