osom_lib_trees/traits/
comparer.rs1pub trait Compare<TOther> {
3 fn is_less(&self, other: &TOther) -> bool;
5
6 fn is_equal(&self, other: &TOther) -> bool;
8
9 fn is_less_or_equal(&self, other: &TOther) -> bool {
11 self.is_less(other) || self.is_equal(other)
12 }
13
14 fn is_greater(&self, other: &TOther) -> bool {
16 !self.is_less_or_equal(other)
17 }
18
19 fn is_greater_or_equal(&self, other: &TOther) -> bool {
21 !self.is_less(other)
22 }
23
24 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}