Trait lrs::cmp::Ord

Objects that are part of a total order.

Syntax

trait Ord<Rhs = Self> : PartialOrd<Rhs>
    where Rhs: ?Sized,
{
    /* Required methods */
    fn cmp(&self, other: &Rhs) -> Ordering
}

Methods

ReceiverNameDescription
&selfcmp

Compares two objects.

Remarks

This is different from PartialOrd in that two elements can always be ordered: They are either equal or one is smaller than the other.

Since Ord<Rhs>: PartialOrd<Rhs>, it is recommended for PartialOrd to be implemented in terms of Ord:

impl PartialOrd<T> for U {
    fn partial_cmp(&self, other: &T) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

Note that this is merely a library trait and does not influence the comparison operators <, <=, etc. which always use the PartialOrd implementation.

Note that you are not forced to implement this trait reflexively or transitively which is, in general, impossible due to coherence rules imposed by the compiler.

Examples

Integers, strings, etc.

See also