Create ex5.rs
This commit is contained in:
parent
662c651c6f
commit
253ff9d75c
21
ex5.rs
Normal file
21
ex5.rs
Normal 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);
|
||||||
|
}
|
Reference in New Issue
Block a user