diff --git a/ex5.rs b/ex5.rs new file mode 100644 index 00000000..661b15ea --- /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); +}