summaryrefslogtreecommitdiff
path: root/advanced/adv-traits/src/main.rs
blob: 6ec0aacf4bedc5469c18b18dd7057648018d2c8c (plain) (blame)
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
32
33
34
//fn main() {
//    println!("Hello, world!");
//}
//
//pub trait Iterator {
//    type Item;
//
//    fn next(&mut self) -> Option<Self::Item>;
//}
//
use std::ops::Add;

#[derive(Debug, PartialEq)]
struct Point {
    x: i32,
    y: i32,
}

impl Add for Point {
    type Output = Point;

    fn add(self, other: Point) -> Point {
        Point {
            x: self.x + other.x,
            y: self.y + other.y,
        }
    }
}

fn main() {
    assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
               Point { x: 3, y: 3 });
    println!("Done.");
}