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