Create ex5.rs

This commit is contained in:
Carol (Nichols || Goulding) 2015-09-16 09:49:09 -04:00
parent 662c651c6f
commit 253ff9d75c
1 changed files with 21 additions and 0 deletions

21
ex5.rs Normal file
View File

@ -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);
}