]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | use std::ops::Add; |
2 | ||
136023e0 | 3 | #[derive(Debug, Copy, Clone, PartialEq)] |
74b04a01 XL |
4 | struct Point { |
5 | x: i32, | |
6 | y: i32, | |
7 | } | |
8 | ||
9 | impl Add for Point { | |
10 | type Output = Point; | |
11 | ||
12 | fn add(self, other: Point) -> Point { | |
13 | Point { | |
14 | x: self.x + other.x, | |
15 | y: self.y + other.y, | |
16 | } | |
17 | } | |
18 | } | |
19 | ||
20 | fn main() { | |
21 | assert_eq!( | |
22 | Point { x: 1, y: 0 } + Point { x: 2, y: 3 }, | |
23 | Point { x: 3, y: 3 } | |
24 | ); | |
25 | } |