More code.
Change-Id: I565975f1936bcdf993c0b17175a1906a1561130e
diff --git a/src/bin/tut4.rs b/src/bin/tut4.rs
index f743435..2894eb6 100644
--- a/src/bin/tut4.rs
+++ b/src/bin/tut4.rs
@@ -1,9 +1,27 @@
-// Fearless Concurrency
+// Generic Programming: Dynamic Polymorphism
#![allow(dead_code)]
#![allow(unused_imports)]
use rust_tutorial::*;
+fn stringify_all(xs: Vec<&dyn ToString>) -> String {
+ let strings: Vec<String> =
+ xs.iter().map(|x| x.to_string()).collect();
+
+ strings.join(", ")
+}
+
fn main() {
+ let mut stringlike_things: Vec<&dyn ToString> = Vec::new();
+
+ let x1 = "abc";
+ let x2 = 100;
+ let x3 = Person { age: 30, name: "Mary".to_string() };
+
+ stringlike_things.push(&x1);
+ stringlike_things.push(&x2);
+ stringlike_things.push(&x3);
+
+ println!("{}", stringify_all(stringlike_things));
}