1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-12-04 10:35:06 +02:00

Create ex5.rs

This commit is contained in:
Carol (Nichols || Goulding) 2015-09-16 09:49:09 -04:00
parent 662c651c6f
commit 253ff9d75c

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