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