Comparator

Trait Comparator 

Source
pub trait Comparator<Key: ?Sized> {
    // Required method
    fn cmp(&self, lhs: &Key, rhs: &Key) -> Ordering;
}
Expand description

Interface for comparing keys (or entries) of a sorted collection.

The comparison function should provide a total order, just as Ord would. Additionally, any clones of a comparator value should behave identically to the source comparator.

Note that none of the axioms that define a total order require that two elements which compare as equal are “truly” equal in some more fundamental sense; that is, keys which are distinct (perhaps according to an Eq implementation) may compare as equal in the provided total order and corresponding equivalence relation.

Unsafe code is not allowed to rely on the correctness of implementations; that is, an incorrect Comparator implementation may cause severe logic errors, but must not cause memory unsafety.

Required Methods§

Source

fn cmp(&self, lhs: &Key, rhs: &Key) -> Ordering

Compare two keys (or entries) in a sorted collection.

This method is analogous to Ord::cmp, and should provide a total order.

Note that none of the axioms that define a total order require that two elements which compare as equal are “truly” equal in some more fundamental sense; that is, keys which are distinct (perhaps according to an Eq implementation) may compare as equal in the provided total order and corresponding equivalence relation.

Unsafe code is not allowed to rely on the correctness of implementations; that is, an incorrect implementation may cause severe logic errors, but must not cause memory unsafety.

Implementations on Foreign Types§

Source§

impl<T, C, Key> Comparator<Key> for GenericContainer<T, C>
where T: ?Sized + Comparator<Key>, C: ?Sized + FragileContainer<T>, Key: ?Sized,

Available on crate feature generic-container only.
Source§

fn cmp(&self, lhs: &Key, rhs: &Key) -> Ordering

Implementors§

Source§

impl<Key: ?Sized + Ord> Comparator<Key> for OrdComparator

Source§

impl<Key: ?Sized, C: FragileContainer<dyn Comparator<Key>>> Comparator<Key> for C

Available on crate feature generic-container only.