summaryrefslogtreecommitdiffstats
path: root/vendor/derive_more/tests/sum.rs
blob: a0b0967bd91d08c69c33269bcac93dd68967d8f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#[macro_use]
extern crate derive_more;

#[derive(Sum)]
struct MyInts(i32, i64);

// Add implementation is needed for Sum
impl ::core::ops::Add for MyInts {
    type Output = MyInts;
    #[inline]
    fn add(self, rhs: MyInts) -> MyInts {
        MyInts(self.0.add(rhs.0), self.1.add(rhs.1))
    }
}

#[derive(Sum)]
struct Point2D {
    x: i32,
    y: i32,
}

impl ::core::ops::Add for Point2D {
    type Output = Point2D;
    #[inline]
    fn add(self, rhs: Point2D) -> Point2D {
        Point2D {
            x: self.x.add(rhs.x),
            y: self.y.add(rhs.y),
        }
    }
}