summaryrefslogtreecommitdiffstats
path: root/examples/14_point-show.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/14_point-show.rs
downloadintro-to-rust-yapc-na-2014-master.tar.gz
intro-to-rust-yapc-na-2014-master.zip
initial commitHEADmaster
Diffstat (limited to 'examples/14_point-show.rs')
-rw-r--r--examples/14_point-show.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/14_point-show.rs b/examples/14_point-show.rs
new file mode 100644
index 0000000..fb21ab1
--- /dev/null
+++ b/examples/14_point-show.rs
@@ -0,0 +1,19 @@
+use std::fmt::{Show,Formatter,FormatError};
+
+struct Point {
+ x: int,
+ y: int,
+}
+
+impl Show for Point {
+ fn fmt (&self, f: &mut Formatter) -> Result<(), FormatError> {
+ try!(write!(f, "({}, {})", self.x, self.y));
+ return Ok(());
+ }
+}
+
+fn main () {
+ let p1 = Point { x: 1, y: 2 };
+ println!("{}", p1);
+}
+