Ordering enumv0.1.0
pub enum Ordering: int8 {
Less = -1,
Equal = 0,
Greater = 1
}
The discriminants are -1, 0 and 1 stored in an int8, so an ordering costs one byte and its sign is the
comparison's sign. A comparison that cannot decide has no representation here: every pair a comparison is asked
about must land on exactly one of these three.
Ordering is a Copy value, so reading one never consumes it.
Cases
| Name | Value | Description |
|---|---|---|
Less | -1 | The left value comes before the right one. |
Equal | 0 | Neither comes first; the two order the same. |
Greater | 1 | The left value comes after the right one. |
Methods
IsLess
pub func IsLess(self: &Ordering) -> bool
Reports whether the left side of the comparison was the smaller one.
Borrows the ordering through self and leaves it untouched.
Cannot fail. Runs in constant time and allocates nothing.
Returns: whether this ordering is Less
IsEqual
pub func IsEqual(self: &Ordering) -> bool
Reports whether the two sides compared equal.
Borrows the ordering through self and leaves it untouched.
Cannot fail. Runs in constant time and allocates nothing.
Returns: whether this ordering is Equal
IsGreater
pub func IsGreater(self: &Ordering) -> bool
Reports whether the left side of the comparison was the larger one.
Borrows the ordering through self and leaves it untouched.
Cannot fail. Runs in constant time and allocates nothing.
Returns: whether this ordering is Greater
IsLessOrEqual
pub func IsLessOrEqual(self: &Ordering) -> bool
Reports whether the left side was smaller than or equal to the right.
Borrows the ordering through self and leaves it untouched. This is the negation of IsGreater, spelled out
so a caller testing a bound does not have to negate one.
Cannot fail. Runs in constant time and allocates nothing.
Returns: whether this ordering is Less or Equal
IsGreaterOrEqual
pub func IsGreaterOrEqual(self: &Ordering) -> bool
Reports whether the left side was larger than or equal to the right.
Borrows the ordering through self and leaves it untouched. This is the negation of IsLess.
Cannot fail. Runs in constant time and allocates nothing.
Returns: whether this ordering is Greater or Equal
Reverse
pub func Reverse(self: Ordering) -> Ordering
The ordering the same comparison would have given with its two sides swapped.
Consumes the ordering by value and returns a new one; Less and Greater trade places while Equal is its
own reverse. A Copy value, so the caller's own ordering is unaffected.
Cannot fail. Runs in constant time and allocates nothing.
Returns: the opposite ordering, with Equal unchanged