1extern crate overload;
2use overload::overload;
3use std::ops;
4
5#[derive(PartialEq, Debug)]
6struct A(i32);
7
8#[derive(PartialEq, Debug)]
9struct B(i32);
10
11overload!((a: &mut A) += (b: B) { a.0 += b.0; });
12#[test]
13fn add_assign() {
14 let mut a = A(3);
15 a += B(4);
16 assert_eq!(A(3 + 4), a);
17}
18
19overload!((a: &mut A) -= (b: B) { a.0 -= b.0; });
20#[test]
21fn sub_assign() {
22 let mut a = A(3);
23 a -= B(4);
24 assert_eq!(A(3 - 4), a);
25}
26
27overload!((a: &mut A) *= (b: B) { a.0 *= b.0; });
28#[test]
29fn mul_assign() {
30 let mut a = A(3);
31 a *= B(4);
32 assert_eq!(A(3 * 4), a);
33}
34
35overload!((a: &mut A) /= (b: B) { a.0 /= b.0; });
36#[test]
37fn div_assign() {
38 let mut a = A(6);
39 a /= B(3);
40 assert_eq!(A(6 / 3), a);
41}
42
43overload!((a: &mut A) %= (b: B) { a.0 %= b.0; });
44#[test]
45fn rem_assign() {
46 let mut a = A(6);
47 a %= B(4);
48 assert_eq!(A(6 % 4), a);
49}
50
51overload!((a: &mut A) &= (b: B) { a.0 &= b.0; });
52#[test]
53fn bitand_assign() {
54 let mut a = A(6);
55 a &= B(4);
56 assert_eq!(A(6 & 4), a);
57}
58
59overload!((a: &mut A) |= (b: B) { a.0 |= b.0; });
60#[test]
61fn bitor_assign() {
62 let mut a = A(6);
63 a |= B(4);
64 assert_eq!(A(6 | 4), a);
65}
66
67overload!((a: &mut A) ^= (b: B) { a.0 ^= b.0; });
68#[test]
69fn bitxor_assign() {
70 let mut a = A(6);
71 a ^= B(4);
72 assert_eq!(A(6 ^ 4), a);
73}
74
75overload!((a: &mut A) <<= (b: B) { a.0 <<= b.0; });
76#[test]
77fn shl_assign() {
78 let mut a = A(6);
79 a <<= B(4);
80 assert_eq!(A(6 << 4), a);
81}
82
83overload!((a: &mut A) >>= (b: B) { a.0 >>= b.0; });
84#[test]
85fn shr_assign() {
86 let mut a = A(6);
87 a >>= B(4);
88 assert_eq!(A(6 >> 4), a);
89}
90