From 963fe0a864ff9e591c294ea0b513fbf4fa6ef504 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 31 Aug 2016 11:18:25 -0400 Subject: [PATCH] Through 1.2.2.1 --- rustbyexample/01221/Cargo.lock | 4 ++++ rustbyexample/01221/Cargo.toml | 6 ++++++ rustbyexample/01221/src/main.rs | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 rustbyexample/01221/Cargo.lock create mode 100644 rustbyexample/01221/Cargo.toml create mode 100644 rustbyexample/01221/src/main.rs diff --git a/rustbyexample/01221/Cargo.lock b/rustbyexample/01221/Cargo.lock new file mode 100644 index 0000000..4f28163 --- /dev/null +++ b/rustbyexample/01221/Cargo.lock @@ -0,0 +1,4 @@ +[root] +name = "01221" +version = "0.1.0" + diff --git a/rustbyexample/01221/Cargo.toml b/rustbyexample/01221/Cargo.toml new file mode 100644 index 0000000..53aae60 --- /dev/null +++ b/rustbyexample/01221/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "01221" +version = "0.1.0" +authors = ["Dan Buch "] + +[dependencies] diff --git a/rustbyexample/01221/src/main.rs b/rustbyexample/01221/src/main.rs new file mode 100644 index 0000000..f28d417 --- /dev/null +++ b/rustbyexample/01221/src/main.rs @@ -0,0 +1,23 @@ +use std::fmt; + +struct List(Vec); + +impl fmt::Display for List { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let List(ref vec) = *self; + + try!(write!(f, "[")); + + for (count, v) in vec.iter().enumerate() { + if count != 0 { try!(write!(f, ", ")); } + try!(write!(f, "{}", v)); + } + + write!(f, "]") + } +} + +fn main() { + let v = List(vec![1, 2, 3]); + println!("{}", v); +}