summaryrefslogtreecommitdiff
path: root/advanced/adv-traits/src
diff options
context:
space:
mode:
authorAdam Carpenter <53hornet@gmail.com>2019-03-21 17:10:15 -0400
committerAdam Carpenter <53hornet@gmail.com>2019-03-21 17:10:15 -0400
commit333965318a5d000140d54be2a2a9e0832372f271 (patch)
treee7f28b53144982cfdf2cb95c9d71e5ea7a566b77 /advanced/adv-traits/src
parent2fadb006603139c335ed8df8fa9c25402986c4fd (diff)
downloadlearning-rust-333965318a5d000140d54be2a2a9e0832372f271.tar.xz
learning-rust-333965318a5d000140d54be2a2a9e0832372f271.zip
Added advanced features.
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.");
+}