mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-21 13:32:23 -05:00
Create ex5.rs
This commit is contained in:
parent
662c651c6f
commit
253ff9d75c
1 changed files with 21 additions and 0 deletions
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);
|
||||
}
|
Loading…
Reference in a new issue