ospf_rust_math/algebra/operator/comparison/
mod.rs

1use std::cmp::Ordering;
2
3pub use compare::*;
4pub use equal::*;
5pub use greater::*;
6pub use greater_equal::*;
7pub use less::*;
8pub use less_equal::*;
9pub use unequal::*;
10pub use zero::*;
11
12pub mod compare;
13pub mod equal;
14pub mod greater;
15pub mod greater_equal;
16pub mod less;
17pub mod less_equal;
18pub mod unequal;
19pub mod zero;
20
21pub trait ComparisonOperator<Lhs, Rhs = Lhs> {
22    fn cmp(&self, lhs: &Lhs, rhs: &Rhs) -> bool;
23}
24
25impl<T, Rhs> FnOnce<(&T, &Rhs)> for &dyn ComparisonOperator<T, Rhs> {
26    type Output = bool;
27
28    extern "rust-call" fn call_once(self, (x, y): (&T, &Rhs)) -> bool {
29        self.cmp(x, y)
30    }
31}
32
33impl<T, Rhs> FnMut<(&T, &Rhs)> for &dyn ComparisonOperator<T, Rhs> {
34    extern "rust-call" fn call_mut(&mut self, (x, y): (&T, &Rhs)) -> bool {
35        self.cmp(x, y)
36    }
37}
38
39impl<T, Rhs> Fn<(&T, &Rhs)> for &dyn ComparisonOperator<T, Rhs> {
40    extern "rust-call" fn call(&self, (x, y): (&T, &Rhs)) -> bool {
41        self.cmp(x, y)
42    }
43}
44
45impl<T, Rhs> FnOnce<(&T, &Rhs)> for Box<dyn ComparisonOperator<T, Rhs>> {
46    type Output = bool;
47
48    extern "rust-call" fn call_once(self, (x, y): (&T, &Rhs)) -> bool {
49        self.cmp(x, y)
50    }
51}
52
53impl<T, Rhs> FnMut<(&T, &Rhs)> for Box<dyn ComparisonOperator<T, Rhs>> {
54    extern "rust-call" fn call_mut(&mut self, (x, y): (&T, &Rhs)) -> bool {
55        self.cmp(x, y)
56    }
57}
58
59impl<T, Rhs> Fn<(&T, &Rhs)> for Box<dyn ComparisonOperator<T, Rhs>> {
60    extern "rust-call" fn call(&self, (x, y): (&T, &Rhs)) -> bool {
61        self.cmp(x, y)
62    }
63}
64
65pub trait ThreeWayComparisonOperator<Lhs, Rhs = Lhs> {
66    fn cmp(&self, lhs: &Lhs, rhs: &Rhs) -> Option<Ordering>;
67}
68
69impl<T, Rhs> FnOnce<(&T, &Rhs)> for &dyn ThreeWayComparisonOperator<T, Rhs> {
70    type Output = Option<Ordering>;
71
72    extern "rust-call" fn call_once(self, (x, y): (&T, &Rhs)) -> Option<Ordering> {
73        self.cmp(x, y)
74    }
75}
76
77impl<T, Rhs> FnMut<(&T, &Rhs)> for &dyn ThreeWayComparisonOperator<T, Rhs> {
78    extern "rust-call" fn call_mut(&mut self, (x, y): (&T, &Rhs)) -> Option<Ordering> {
79        self.cmp(x, y)
80    }
81}
82
83impl<T, Rhs> Fn<(&T, &Rhs)> for &dyn ThreeWayComparisonOperator<T, Rhs> {
84    extern "rust-call" fn call(&self, (x, y): (&T, &Rhs)) -> Option<Ordering> {
85        self.cmp(x, y)
86    }
87}
88
89impl<T, Rhs> FnOnce<(&T, &Rhs)> for Box<dyn ThreeWayComparisonOperator<T, Rhs>> {
90    type Output = Option<Ordering>;
91
92    extern "rust-call" fn call_once(self, (x, y): (&T, &Rhs)) -> Option<Ordering> {
93        self.cmp(x, y)
94    }
95}
96
97impl<T, Rhs> FnMut<(&T, &Rhs)> for Box<dyn ThreeWayComparisonOperator<T, Rhs>> {
98    extern "rust-call" fn call_mut(&mut self, (x, y): (&T, &Rhs)) -> Option<Ordering> {
99        self.cmp(x, y)
100    }
101}
102
103impl<T, Rhs> Fn<(&T, &Rhs)> for Box<dyn ThreeWayComparisonOperator<T, Rhs>> {
104    extern "rust-call" fn call(&self, (x, y): (&T, &Rhs)) -> Option<Ordering> {
105        self.cmp(x, y)
106    }
107}