1macro_rules! impl_add_to_wrapper {
2 ( $wrapper:ident, $inner:ty ) => {
3 use std::ops::{Add, AddAssign};
4
5 impl Add for $wrapper {
6 type Output = Self;
7
8 fn add(self, rhs: Self) -> Self::Output {
9 self + *rhs
10 }
11 }
12
13 impl Add<$inner> for $wrapper {
14 type Output = Self;
15
16 fn add(self, rhs: $inner) -> Self::Output {
17 $wrapper(*self + rhs)
18 }
19 }
20
21 impl Add<&$inner> for $wrapper {
22 type Output = Self;
23
24 fn add(self, rhs: &$inner) -> Self::Output {
25 self.add(*rhs)
26 }
27 }
28
29 impl Add<$wrapper> for $inner {
30 type Output = $wrapper;
31
32 fn add(self, rhs: $wrapper) -> Self::Output {
33 rhs.add(self)
34 }
35 }
36
37 impl Add<&$wrapper> for $inner {
38 type Output = $wrapper;
39
40 fn add(self, rhs: &$wrapper) -> Self::Output {
41 rhs.add(self)
42 }
43 }
44
45 impl Add<$wrapper> for &$inner {
46 type Output = $wrapper;
47
48 fn add(self, rhs: $wrapper) -> Self::Output {
49 rhs.add(self)
50 }
51 }
52
53 impl Add<&$wrapper> for &$inner {
54 type Output = $wrapper;
55
56 fn add(self, rhs: &$wrapper) -> Self::Output {
57 rhs.add(self)
58 }
59 }
60
61 impl AddAssign for $wrapper {
62 fn add_assign(&mut self, rhs: Self) {
63 *self = self.add(rhs);
64 }
65 }
66
67 impl AddAssign<$inner> for $wrapper {
68 fn add_assign(&mut self, rhs: $inner) {
69 *self = self.add(rhs);
70 }
71 }
72
73 impl AddAssign<&$inner> for $wrapper {
74 fn add_assign(&mut self, rhs: &$inner) {
75 *self = self.add(rhs);
76 }
77 }
78
79 impl AddAssign<$wrapper> for $inner {
80 fn add_assign(&mut self, rhs: $wrapper) {
81 *self = self.add(rhs.0);
82 }
83 }
84
85 impl AddAssign<&$wrapper> for $inner {
86 fn add_assign(&mut self, rhs: &$wrapper) {
87 *self = self.add(rhs.0);
88 }
89 }
90 };
91}
92pub(crate) use impl_add_to_wrapper;
93
94macro_rules! impl_sub_to_wrapper {
95 ( $wrapper:ident, $inner:ty ) => {
96 use std::ops::{Sub, SubAssign};
97
98 impl Sub for $wrapper {
99 type Output = Self;
100
101 fn sub(self, rhs: Self) -> Self::Output {
102 self - *rhs
103 }
104 }
105
106 impl Sub<$inner> for $wrapper {
107 type Output = Self;
108
109 fn sub(self, rhs: $inner) -> Self::Output {
110 $wrapper(self.saturating_sub(rhs))
111 }
112 }
113
114 impl Sub<&$inner> for $wrapper {
115 type Output = Self;
116
117 fn sub(self, rhs: &$inner) -> Self::Output {
118 self.sub(*rhs)
119 }
120 }
121
122 impl Sub<$wrapper> for $inner {
123 type Output = $wrapper;
124
125 fn sub(self, rhs: $wrapper) -> Self::Output {
126 rhs.sub(self)
127 }
128 }
129
130 impl Sub<&$wrapper> for $inner {
131 type Output = $wrapper;
132
133 fn sub(self, rhs: &$wrapper) -> Self::Output {
134 rhs.sub(self)
135 }
136 }
137
138 impl Sub<$wrapper> for &$inner {
139 type Output = $wrapper;
140
141 fn sub(self, rhs: $wrapper) -> Self::Output {
142 rhs.sub(self)
143 }
144 }
145
146 impl Sub<&$wrapper> for &$inner {
147 type Output = $wrapper;
148
149 fn sub(self, rhs: &$wrapper) -> Self::Output {
150 rhs.sub(self)
151 }
152 }
153
154 impl SubAssign for $wrapper {
155 fn sub_assign(&mut self, rhs: Self) {
156 *self = self.sub(rhs);
157 }
158 }
159
160 impl SubAssign<$inner> for $wrapper {
161 fn sub_assign(&mut self, rhs: $inner) {
162 *self = self.sub(rhs);
163 }
164 }
165
166 impl SubAssign<&$inner> for $wrapper {
167 fn sub_assign(&mut self, rhs: &$inner) {
168 *self = self.sub(rhs);
169 }
170 }
171
172 impl SubAssign<$wrapper> for $inner {
173 fn sub_assign(&mut self, rhs: $wrapper) {
174 *self = self.sub(rhs.0);
175 }
176 }
177
178 impl SubAssign<&$wrapper> for $inner {
179 fn sub_assign(&mut self, rhs: &$wrapper) {
180 *self = self.sub(rhs.0);
181 }
182 }
183 };
184}
185pub(crate) use impl_sub_to_wrapper;
186
187macro_rules! impl_mul_to_wrapper {
188 ( $wrapper:ident, $inner:ty ) => {
189 use std::ops::{Mul, MulAssign};
190
191 impl Mul for $wrapper {
192 type Output = Self;
193
194 fn mul(self, rhs: Self) -> Self::Output {
195 self * *rhs
196 }
197 }
198
199 impl Mul<$inner> for $wrapper {
200 type Output = Self;
201
202 fn mul(self, rhs: $inner) -> Self::Output {
203 $wrapper(*self * rhs)
204 }
205 }
206
207 impl Mul<&$inner> for $wrapper {
208 type Output = Self;
209
210 fn mul(self, rhs: &$inner) -> Self::Output {
211 self.mul(*rhs)
212 }
213 }
214
215 impl Mul<$wrapper> for $inner {
216 type Output = $wrapper;
217
218 fn mul(self, rhs: $wrapper) -> Self::Output {
219 rhs.mul(self)
220 }
221 }
222
223 impl Mul<&$wrapper> for $inner {
224 type Output = $wrapper;
225
226 fn mul(self, rhs: &$wrapper) -> Self::Output {
227 rhs.mul(self)
228 }
229 }
230
231 impl Mul<$wrapper> for &$inner {
232 type Output = $wrapper;
233
234 fn mul(self, rhs: $wrapper) -> Self::Output {
235 rhs.mul(self)
236 }
237 }
238
239 impl Mul<&$wrapper> for &$inner {
240 type Output = $wrapper;
241
242 fn mul(self, rhs: &$wrapper) -> Self::Output {
243 rhs.mul(self)
244 }
245 }
246
247 impl MulAssign for $wrapper {
248 fn mul_assign(&mut self, rhs: Self) {
249 *self = self.mul(rhs);
250 }
251 }
252
253 impl MulAssign<$inner> for $wrapper {
254 fn mul_assign(&mut self, rhs: $inner) {
255 *self = self.mul(rhs);
256 }
257 }
258
259 impl MulAssign<&$inner> for $wrapper {
260 fn mul_assign(&mut self, rhs: &$inner) {
261 *self = self.mul(rhs);
262 }
263 }
264
265 impl MulAssign<$wrapper> for $inner {
266 fn mul_assign(&mut self, rhs: $wrapper) {
267 *self = self.mul(rhs.0);
268 }
269 }
270
271 impl MulAssign<&$wrapper> for $inner {
272 fn mul_assign(&mut self, rhs: &$wrapper) {
273 *self = self.mul(rhs.0);
274 }
275 }
276 };
277}
278pub(crate) use impl_mul_to_wrapper;
279
280macro_rules! impl_div_to_wrapper {
281 ( $wrapper:ident, $inner:ty ) => {
282 use std::ops::{Div, DivAssign};
283
284 impl Div for $wrapper {
285 type Output = Self;
286
287 fn div(self, rhs: Self) -> Self::Output {
288 self / *rhs
289 }
290 }
291
292 impl Div<$inner> for $wrapper {
293 type Output = Self;
294
295 fn div(self, rhs: $inner) -> Self::Output {
296 $wrapper(*self / rhs)
297 }
298 }
299
300 impl Div<&$inner> for $wrapper {
301 type Output = Self;
302
303 fn div(self, rhs: &$inner) -> Self::Output {
304 self.div(*rhs)
305 }
306 }
307
308 impl Div<$wrapper> for $inner {
309 type Output = $wrapper;
310
311 fn div(self, rhs: $wrapper) -> Self::Output {
312 $wrapper(self.div(rhs.0))
313 }
314 }
315
316 impl Div<&$wrapper> for $inner {
317 type Output = $wrapper;
318
319 fn div(self, rhs: &$wrapper) -> Self::Output {
320 self.div(*rhs)
321 }
322 }
323
324 impl Div<$wrapper> for &$inner {
325 type Output = $wrapper;
326
327 fn div(self, rhs: $wrapper) -> Self::Output {
328 (*self).div(rhs)
329 }
330 }
331
332 impl Div<&$wrapper> for &$inner {
333 type Output = $wrapper;
334
335 fn div(self, rhs: &$wrapper) -> Self::Output {
336 (*self).div(*rhs)
337 }
338 }
339
340 impl DivAssign for $wrapper {
341 fn div_assign(&mut self, rhs: Self) {
342 *self = self.div(rhs);
343 }
344 }
345
346 impl DivAssign<$inner> for $wrapper {
347 fn div_assign(&mut self, rhs: $inner) {
348 *self = self.div(rhs);
349 }
350 }
351
352 impl DivAssign<&$inner> for $wrapper {
353 fn div_assign(&mut self, rhs: &$inner) {
354 *self = self.div(rhs);
355 }
356 }
357
358 impl DivAssign<$wrapper> for $inner {
359 fn div_assign(&mut self, rhs: $wrapper) {
360 *self = self.div(rhs.0);
361 }
362 }
363
364 impl DivAssign<&$wrapper> for $inner {
365 fn div_assign(&mut self, rhs: &$wrapper) {
366 *self = self.div(rhs.0);
367 }
368 }
369 };
370}
371pub(crate) use impl_div_to_wrapper;
372
373macro_rules! impl_rem_to_wrapper {
374 ( $wrapper:ident, $inner:ty ) => {
375 use std::ops::{Rem, RemAssign};
376
377 impl Rem for $wrapper {
378 type Output = Self;
379
380 fn rem(self, rhs: Self) -> Self::Output {
381 self % *rhs
382 }
383 }
384
385 impl Rem<$inner> for $wrapper {
386 type Output = Self;
387
388 fn rem(self, rhs: $inner) -> Self::Output {
389 $wrapper(*self % rhs)
390 }
391 }
392
393 impl Rem<&$inner> for $wrapper {
394 type Output = Self;
395
396 fn rem(self, rhs: &$inner) -> Self::Output {
397 self.rem(*rhs)
398 }
399 }
400
401 impl Rem<$wrapper> for $inner {
402 type Output = $wrapper;
403
404 fn rem(self, rhs: $wrapper) -> Self::Output {
405 $wrapper(self.rem(rhs.0))
406 }
407 }
408
409 impl Rem<&$wrapper> for $inner {
410 type Output = $wrapper;
411
412 fn rem(self, rhs: &$wrapper) -> Self::Output {
413 self.rem(*rhs)
414 }
415 }
416
417 impl Rem<$wrapper> for &$inner {
418 type Output = $wrapper;
419
420 fn rem(self, rhs: $wrapper) -> Self::Output {
421 (*self).rem(rhs)
422 }
423 }
424
425 impl Rem<&$wrapper> for &$inner {
426 type Output = $wrapper;
427
428 fn rem(self, rhs: &$wrapper) -> Self::Output {
429 (*self).rem(*rhs)
430 }
431 }
432
433 impl RemAssign for $wrapper {
434 fn rem_assign(&mut self, rhs: Self) {
435 *self = self.rem(rhs);
436 }
437 }
438
439 impl RemAssign<$inner> for $wrapper {
440 fn rem_assign(&mut self, rhs: $inner) {
441 *self = self.rem(rhs);
442 }
443 }
444
445 impl RemAssign<&$inner> for $wrapper {
446 fn rem_assign(&mut self, rhs: &$inner) {
447 *self = self.rem(rhs);
448 }
449 }
450
451 impl RemAssign<$wrapper> for $inner {
452 fn rem_assign(&mut self, rhs: $wrapper) {
453 *self = self.rem(rhs.0);
454 }
455 }
456
457 impl RemAssign<&$wrapper> for $inner {
458 fn rem_assign(&mut self, rhs: &$wrapper) {
459 *self = self.rem(rhs.0);
460 }
461 }
462 };
463}
464pub(crate) use impl_rem_to_wrapper;
465
466macro_rules! impl_partial_eq_to_wrapper {
467 ( $wrapper:ty, $inner:ty ) => {
468 impl PartialEq<$inner> for $wrapper {
469 fn eq(&self, other: &$inner) -> bool {
470 self.0.eq(other)
471 }
472 }
473
474 impl PartialEq<&$inner> for $wrapper {
475 fn eq(&self, other: &&$inner) -> bool {
476 self.0.eq(*other)
477 }
478 }
479
480 impl PartialEq<&$wrapper> for $wrapper {
481 fn eq(&self, other: &&$wrapper) -> bool {
482 other.0.eq(self)
483 }
484 }
485
486 impl PartialEq<$inner> for &$wrapper {
487 fn eq(&self, other: &$inner) -> bool {
488 self.0.eq(other)
489 }
490 }
491
492 impl PartialEq<$wrapper> for &$wrapper {
493 fn eq(&self, other: &$wrapper) -> bool {
494 other.0.eq(self)
495 }
496 }
497
498 impl PartialEq<$wrapper> for $inner {
499 fn eq(&self, other: &$wrapper) -> bool {
500 other.0.eq(self)
501 }
502 }
503
504 impl PartialEq<&$wrapper> for $inner {
505 fn eq(&self, other: &&$wrapper) -> bool {
506 other.0.eq(self)
507 }
508 }
509
510 impl PartialEq<$wrapper> for &$inner {
511 fn eq(&self, other: &$wrapper) -> bool {
512 other.0.eq(*self)
513 }
514 }
515 };
516}
517pub(crate) use impl_partial_eq_to_wrapper;
518
519#[cfg(test)]
520pub(crate) mod tests {
521 macro_rules! test_op_assign {
522 ( $right:expr, +=, $left:expr => $expected:expr ) => {{
523 let mut number = $right;
524 number += $left;
525 assert_eq!($expected, number);
526 }};
527 ( $right:expr, -=, $left:expr => $expected:expr ) => {{
528 let mut number = $right;
529 number -= $left;
530 assert_eq!($expected, number);
531 }};
532 ( $right:expr, *=, $left:expr => $expected:expr ) => {{
533 let mut number = $right;
534 number *= $left;
535 assert_eq!($expected, number);
536 }};
537 ( $right:expr, /=, $left:expr => $expected:expr ) => {{
538 let mut number = $right;
539 number /= $left;
540 assert_eq!($expected, number);
541 }};
542 ( $right:expr, %=, $left:expr => $expected:expr ) => {{
543 let mut number = $right;
544 number %= $left;
545 assert_eq!($expected, number);
546 }};
547 }
548 pub(crate) use test_op_assign;
549}