From 253ff9d75c0312f5486e5a5eaa5be12ad65ee696 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 16 Sep 2015 09:49:09 -0400 Subject: [PATCH] Create ex5.rs --- ex5.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ex5.rs diff --git a/ex5.rs b/ex5.rs new file mode 100644 index 0000000..661b15e --- /dev/null +++ b/ex5.rs @@ -0,0 +1,21 @@ +// Make me compile! + +enum Reaction<'a> { + Sad(&'a str), + Happy(&'a str), +} + +fn express(sentiment: Reaction) { + match sentiment { + Reaction::Sad(s) => println!(":( {}", s), + Reaction::Happy(s) => println!(":) {}", s), + } +} + +fn main () { + let x = Reaction::Happy("It's a great day for Rust!"); + express(x); + express(x); + let y = Reaction::Sad("This code doesn't compile yet."); + express(y); +}