Protocol std::cmp::LexicographicComparable
Mixin to provide a default implementation of Comparable for a type
This mixin provides a default implementation of compare for a type. If the type is a struct, it will compare each field lexicographically in order of declaration. If the type is an enum, it will compare the underlying value.
If any field is not comparable, this will result in a compilation error.
Example
struct FullName { first: &[u8], last: &[u8] }
impl FullName {
use std::cmp::LexicographicComparable;
mixin LexicographicComparable<FullName>;
}
assert!(FullName { first: "John", last: "Malkovich" } < FullName { first: "John", last: "McCain" });
assert!(FullName { first: "John", last: "Doe" } == FullName { first: "John", last: "Doe" });
Run this example
Provided methods
-
Returns
true
iflhs
is equal torhs
,false
otherwise -
Returns
true
iflhs
not equal torhs
,false
otherwise -
Returns
true
iflhs
is strictly less thanrhs
,false
otherwise -
Returns
true
iflhs
is less or equal torhs
,false
otherwise -
Returns
true
iflhs
strictly greater thanrhs
,false
otherwise -
Returns
true
iflhs
greater than or equalrhs
,false
otherwise