summaryrefslogtreecommitdiffstats
path: root/examples/12_point-impl.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-07-02 02:54:21 -0400
committerJesse Luehrs <doy@tozt.net>2014-07-02 02:54:21 -0400
commite620daf3b1a40ae825c625bc4328fb7d2b3ee8b6 (patch)
treefaa469408ee78623eaa8d2720dcbb36096788ca1 /examples/12_point-impl.rs
downloadintro-to-rust-yapc-na-2014-e620daf3b1a40ae825c625bc4328fb7d2b3ee8b6.tar.gz
intro-to-rust-yapc-na-2014-e620daf3b1a40ae825c625bc4328fb7d2b3ee8b6.zip
initial commitHEADmaster
Diffstat (limited to 'examples/12_point-impl.rs')
-rw-r--r--examples/12_point-impl.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/12_point-impl.rs b/examples/12_point-impl.rs
new file mode 100644
index 0000000..302f787
--- /dev/null
+++ b/examples/12_point-impl.rs
@@ -0,0 +1,16 @@
+struct Point {
+ x: int,
+ y: int,
+}
+
+impl Point {
+ fn new (x: int, y: int) -> Point { Point { x: x, y: y } }
+ fn x (&self) -> int { self.x }
+ fn y (&self) -> int { self.y }
+}
+
+fn main () {
+ let p1 = Point::new(1, 2);
+ println!("({}, {})", p1.x(), p1.y());
+}
+