osom_lib_trees/traits/
comparer.rs

1/// Represents a comparer for two values.
2pub trait Compare<TOther> {
3    /// Checks if `self < other`.
4    fn is_less(&self, other: &TOther) -> bool;
5
6    /// Checks if `self == other`.
7    fn is_equal(&self, other: &TOther) -> bool;
8
9    /// Checks if `self <= other`. This should be equivalent to `self < other || self == other`.
10    fn is_less_or_equal(&self, other: &TOther) -> bool {
11        self.is_less(other) || self.is_equal(other)
12    }
13
14    /// Checks if `self > other`. This should be equivalent to `!(self <= other)`.
15    fn is_greater(&self, other: &TOther) -> bool {
16        !self.is_less_or_equal(other)
17    }
18
19    /// Checks if `self >= other`. This should be equivalent to `self > other || self == other`.
20    fn is_greater_or_equal(&self, other: &TOther) -> bool {
21        !self.is_less(other)
22    }
23
24    /// Checks if `self != other`. This should be equivalent to `!(self == other)`.
25    fn is_not_equal(&self, other: &TOther) -> bool {
26        !self.is_equal(other)
27    }
28}
29
30impl<T, K> Compare<K> for T
31where
32    T: Ord,
33    K: core::borrow::Borrow<T>,
34{
35    fn is_less(&self, other: &K) -> bool {
36        self < other.borrow()
37    }
38
39    fn is_equal(&self, other: &K) -> bool {
40        self == other.borrow()
41    }
42}