]> git.proxmox.com Git - rustc.git/blame - src/doc/book/listings/ch19-advanced-features/listing-19-14/src/main.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / doc / book / listings / ch19-advanced-features / listing-19-14 / src / main.rs
CommitLineData
74b04a01
XL
1use std::ops::Add;
2
136023e0 3#[derive(Debug, Copy, Clone, PartialEq)]
74b04a01
XL
4struct Point {
5 x: i32,
6 y: i32,
7}
8
9impl 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
20fn main() {
21 assert_eq!(
22 Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
23 Point { x: 3, y: 3 }
24 );
25}