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 | #[derive(PartialEq, Debug)]
|
12 | struct C(i32);
|
13 |
|
14 | overload!((a: A) + (b: B) -> C { C(a.0 + b.0) });
|
15 | #[test]
|
16 | fn add() {
|
17 | assert_eq!(A(3) + B(4), C(3 + 4));
|
18 | }
|
19 |
|
20 | overload!((a: A) - (b: B) -> C { C(a.0 - b.0) });
|
21 | #[test]
|
22 | fn sub() {
|
23 | assert_eq!(A(3) - B(4), C(3 - 4));
|
24 | }
|
25 |
|
26 | overload!((a: A) * (b: B) -> C { C(a.0 * b.0) });
|
27 | #[test]
|
28 | fn mul() {
|
29 | assert_eq!(A(3) * B(4), C(3 * 4));
|
30 | }
|
31 |
|
32 | overload!((a: A) / (b: B) -> C { C(a.0 / b.0) });
|
33 | #[test]
|
34 | fn div() {
|
35 | assert_eq!(A(6) / B(3), C(6 / 3));
|
36 | }
|
37 |
|
38 | overload!((a: A) % (b: B) -> C { C(a.0 % b.0) });
|
39 | #[test]
|
40 | fn rem() {
|
41 | assert_eq!(A(6) % B(4), C(6 % 4));
|
42 | }
|
43 |
|
44 | overload!((a: A) & (b: B) -> C { C(a.0 & b.0) });
|
45 | #[test]
|
46 | fn bitand() {
|
47 | assert_eq!(A(6) & B(4), C(6 & 4));
|
48 | }
|
49 |
|
50 | overload!((a: A) | (b: B) -> C { C(a.0 | b.0) });
|
51 | #[test]
|
52 | fn bitor() {
|
53 | assert_eq!(A(6) | B(4), C(6 | 4));
|
54 | }
|
55 |
|
56 | overload!((a: A) ^ (b: B) -> C { C(a.0 ^ b.0) });
|
57 | #[test]
|
58 | fn bitxor() {
|
59 | assert_eq!(A(6) ^ B(4), C(6 ^ 4));
|
60 | }
|
61 |
|
62 | overload!((a: A) << (b: B) -> C { C(a.0 << b.0) });
|
63 | #[test]
|
64 | fn shl() {
|
65 | assert_eq!(A(6) << B(4), C(6 << 4));
|
66 | }
|
67 |
|
68 | overload!((a: A) >> (b: B) -> C { C(a.0 >> b.0) });
|
69 | #[test]
|
70 | fn shr() {
|
71 | assert_eq!(A(6) >> B(4), C(6 >> 4));
|
72 | }
|
73 | |