1#[macro_export]
6macro_rules! impl_ops_cmp {
7 (impl $imp:ident, $imo:ident, $method:ident for $t:ty, $u:ty, $sgn:expr) => {
8impl $imp<$u> for $t {
36 #[inline]
38 fn eq(&self, rhs: &$u) -> bool {
39 self.$method(rhs) == 0
40 }
41 }
42
43 impl $imo<$u> for $t {
46 #[inline]
48 fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
49 let c = self.$method(rhs) * $sgn;
50 if c == 0 { Some(Ordering::Equal) }
51 else if c < 0 { Some(Ordering::Less) }
52 else if c > 0 { Some(Ordering::Greater) }
53 else { None }
54 }
55 }
56 };
57}
58pub use impl_ops_cmp;
59
60#[macro_export]
62macro_rules! impl_ops_cmp_p {
63 (impl $imp:ident, $imo:ident, $method:ident for $t:ty, $u:ty, $sgn:expr) => {
64 impl<'a> $imp<$u> for &'a mut $t {
67 #[inline]
69 fn eq(&self, rhs: &$u) -> bool {
70 self.$method(*rhs) == 0
71 }
72 }
73
74 impl<'a> $imo<$u> for &'a mut $t {
77 #[inline]
79 fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
80 let c = self.$method(*rhs) * $sgn;
81 if c == 0 { Some(Ordering::Equal) }
82 else if c < 0 { Some(Ordering::Less) }
83 else if c > 0 { Some(Ordering::Greater) }
84 else { None }
85 }
86 }
87
88 impl<'a> $imp<$u> for &'a $t {
91 #[inline]
93 fn eq(&self, rhs: &$u) -> bool {
94 self.$method(*rhs) == 0
95 }
96 }
97
98 impl<'a> $imo<$u> for &'a $t {
101 #[inline]
103 fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
104 let c = self.$method(*rhs) * $sgn;
105 if c == 0 { Some(Ordering::Equal) }
106 else if c < 0 { Some(Ordering::Less) }
107 else if c > 0 { Some(Ordering::Greater) }
108 else { None }
109 }
110 }
111
112 impl $imp<$u> for $t {
115 #[inline]
117 fn eq(&self, rhs: &$u) -> bool {
118 self.$method(*rhs) == 0
119 }
120 }
121
122 impl $imo<$u> for $t {
125 #[inline]
127 fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
128 let c = self.$method(*rhs) * $sgn;
129 if c == 0 { Some(Ordering::Equal) }
130 else if c < 0 { Some(Ordering::Less) }
131 else if c > 0 { Some(Ordering::Greater) }
132 else { None }
133 }
134 }
135
136 impl_ops_cmp_q!{impl $imp, $imo, $method for $u, $t, -$sgn}
137 };
138}
139pub use impl_ops_cmp_p;
140
141#[macro_export]
143macro_rules! impl_ops_cmp_q {
144 (impl $imp:ident, $imo:ident, $method:ident for $t:ty, $u:ty, $sgn:expr) => {
145 impl<'a> $imp<&'a mut $u> for $t {
148 #[inline]
150 fn eq(&self, rhs: &&'a mut $u) -> bool {
151 (*rhs).$method(*self) == 0
152 }
153 }
154
155 impl<'a> $imo<&'a mut $u> for $t {
158 #[inline]
160 fn partial_cmp(&self, rhs: &&'a mut $u) -> Option<Ordering> {
161 let c = (*rhs).$method(*self) * $sgn;
162 if c == 0 { Some(Ordering::Equal) }
163 else if c < 0 { Some(Ordering::Less) }
164 else if c > 0 { Some(Ordering::Greater) }
165 else { None }
166 }
167 }
168
169 impl<'a> $imp<&'a $u> for $t {
172 #[inline]
174 fn eq(&self, rhs: &&'a $u) -> bool {
175 (*rhs).$method(*self) == 0
176 }
177 }
178
179 impl<'a> $imo<&'a $u> for $t {
182 #[inline]
184 fn partial_cmp(&self, rhs: &&'a $u) -> Option<Ordering> {
185 let c = (*rhs).$method(*self) * $sgn;
186 if c == 0 { Some(Ordering::Equal) }
187 else if c < 0 { Some(Ordering::Less) }
188 else if c > 0 { Some(Ordering::Greater) }
189 else { None }
190 }
191 }
192
193 impl $imp<$u> for $t {
196 #[inline]
198 fn eq(&self, rhs: &$u) -> bool {
199 rhs.$method(*self) == 0
200 }
201 }
202
203 impl $imo<$u> for $t {
206 #[inline]
208 fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
209 let c = rhs.$method(*self) * $sgn;
210 if c == 0 { Some(Ordering::Equal) }
211 else if c < 0 { Some(Ordering::Less) }
212 else if c > 0 { Some(Ordering::Greater) }
213 else { None }
214 }
215 }
216 };
217}
218pub use impl_ops_cmp_q;