From 333965318a5d000140d54be2a2a9e0832372f271 Mon Sep 17 00:00:00 2001 From: Adam Carpenter <53hornet@gmail.com> Date: Thu, 21 Mar 2019 17:10:15 -0400 Subject: Added advanced features. --- advanced/adv-traits/src/main.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 advanced/adv-traits/src/main.rs (limited to 'advanced/adv-traits/src') diff --git a/advanced/adv-traits/src/main.rs b/advanced/adv-traits/src/main.rs new file mode 100644 index 0000000..6ec0aac --- /dev/null +++ b/advanced/adv-traits/src/main.rs @@ -0,0 +1,34 @@ +//fn main() { +// println!("Hello, world!"); +//} +// +//pub trait Iterator { +// type Item; +// +// fn next(&mut self) -> Option; +//} +// +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."); +} -- cgit v1.2.3