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
trueiflhsis equal torhs,falseotherwise -
Returns
trueiflhsnot equal torhs,falseotherwise -
Returns
trueiflhsis strictly less thanrhs,falseotherwise -
Returns
trueiflhsis less or equal torhs,falseotherwise -
Returns
trueiflhsstrictly greater thanrhs,falseotherwise -
Returns
trueiflhsgreater than or equalrhs,falseotherwise