summaryrefslogtreecommitdiff
path: root/advanced/adv-traits/src
diff options
context:
space:
mode:
Diffstat (limited to 'advanced/adv-traits/src')
-rw-r--r--advanced/adv-traits/src/main.rs34
1 files changed, 34 insertions, 0 deletions
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<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.");
+}