@@ -370,6 +370,99 @@ macro_rules! impl_div_to_wrapper {
370
370
}
371
371
pub ( crate ) use impl_div_to_wrapper;
372
372
373
+ macro_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
+ }
464
+ pub ( crate ) use impl_rem_to_wrapper;
465
+
373
466
macro_rules! impl_partial_eq_to_wrapper {
374
467
( $wrapper: ty, $inner: ty ) => {
375
468
impl PartialEq <$inner> for $wrapper {
@@ -446,6 +539,11 @@ pub(crate) mod tests {
446
539
number /= $left;
447
540
assert_eq!( $expected, number) ;
448
541
} } ;
542
+ ( $right: expr, %=, $left: expr => $expected: expr ) => { {
543
+ let mut number = $right;
544
+ number %= $left;
545
+ assert_eq!( $expected, number) ;
546
+ } } ;
449
547
}
450
548
pub ( crate ) use test_op_assign;
451
549
}
0 commit comments