[−][src]Enum version_compare::comp_op::CompOp
Enum of supported comparison operators.
Variants
EqEqual (==, =).
When version A is equal to B.
NeNot equal (!=, !, <>).
When version A is not equal to B.
LtLess than (<).
When version A is less than B but not equal.
LeLess or equal (<=).
When version A is less than or equal to B.
GeGreater or equal (>=).
When version A is greater than or equal to B.
GtGreater 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->LtOrdering::Equal->EqOrdering::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<->NeLt<->GeLe<->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<->NeLt<->GeLe<->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<->NeLt<->GtLe<->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<->NeLt<->GtLe<->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<->GtLe<->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<->GtLe<->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:
EqorNe->0LtorLe->-1GtorGe->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::EqualLt->Ordering::LessGt->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 PartialEq<CompOp> for CompOp[src]
fn eq(&self, other: &CompOp) -> bool[src]
#[must_use]
default fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl Clone for CompOp[src]
fn clone(&self) -> CompOp[src]
default fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl Debug for CompOp[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
impl<T> From for T[src]
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,