Enum version_compare::Cmp [−][src]
pub enum Cmp {
Eq,
Ne,
Lt,
Le,
Ge,
Gt,
}Expand description
Comparison operators enum.
Variants
Equal (==, =).
When version A is equal to B.
Not equal (!=, !, <>).
When version A is not equal to B.
Less than (<).
When version A is less than B but not equal.
Less or equal (<=).
When version A is less than or equal to B.
Greater or equal (>=).
When version A is greater than or equal to B.
Greater than (>).
When version A is greater than B but not equal.
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:
==or=->Eq!=or!or<>->Ne<->Lt<=->Le>=->Ge>->Gt
Examples
use version_compare::Cmp;
assert_eq!(Cmp::from_sign("=="), Ok(Cmp::Eq));
assert_eq!(Cmp::from_sign("<"), Ok(Cmp::Lt));
assert_eq!(Cmp::from_sign(" >= "), Ok(Cmp::Ge));
assert!(Cmp::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::Cmp;
assert_eq!(Cmp::from_name("eq"), Ok(Cmp::Eq));
assert_eq!(Cmp::from_name("lt"), Ok(Cmp::Lt));
assert_eq!(Cmp::from_name(" Ge "), Ok(Cmp::Ge));
assert!(Cmp::from_name("abc").is_err());Get the comparison operator from Rusts Ordering enum.
The following comparison operators are returned:
Ordering::Less->LtOrdering::Equal->EqOrdering::Greater->Gt
Get the name of this comparison operator.
Examples
use version_compare::Cmp;
assert_eq!(Cmp::Eq.name(), "eq");
assert_eq!(Cmp::Lt.name(), "lt");
assert_eq!(Cmp::Ge.name(), "ge");Get the inverted comparison operator.
This uses the following bidirectional rules:
Eq<->NeLt<->GeLe<->Gt
Examples
use version_compare::Cmp;
assert_eq!(Cmp::Eq.invert(), Cmp::Ne);
assert_eq!(Cmp::Lt.invert(), Cmp::Ge);
assert_eq!(Cmp::Gt.invert(), Cmp::Le);Get the opposite comparison operator.
This uses the following bidirectional rules:
Eq<->NeLt<->GtLe<->Ge
Examples
use version_compare::Cmp;
assert_eq!(Cmp::Eq.opposite(), Cmp::Ne);
assert_eq!(Cmp::Lt.opposite(), Cmp::Gt);
assert_eq!(Cmp::Ge.opposite(), Cmp::Le);Get the flipped comparison operator.
This uses the following bidirectional rules:
Lt<->GtLe<->Ge- Other operators are returned as is.
Examples
use version_compare::Cmp;
assert_eq!(Cmp::Eq.flip(), Cmp::Eq);
assert_eq!(Cmp::Lt.flip(), Cmp::Gt);
assert_eq!(Cmp::Ge.flip(), Cmp::Le);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::Cmp;
assert_eq!(Cmp::Eq.sign(), "==");
assert_eq!(Cmp::Lt.sign(), "<");
assert_eq!(Cmp::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:
EqorNe->0LtorLe->-1GtorGe->1
Examples
use version_compare::Version;
let a = Version::from("1.2.3").unwrap();
let b = Version::from("1.3").unwrap();
assert_eq!(a.compare(&b).factor(), -1);
assert_eq!(10 * b.compare(a).factor(), 10);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 a = Version::from("1.2.3").unwrap();
let b = Version::from("1.3").unwrap();
assert_eq!(a.compare(b).ord().unwrap(), Ordering::Less);Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Cmp
impl UnwindSafe for Cmp
Blanket Implementations
Mutably borrows from an owned value. Read more