mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 00:00:05 +03:00
23 lines
442 B
Rust
Executable file
23 lines
442 B
Rust
Executable file
// ex5.rs
|
|
// 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);
|
|
}
|