Created
July 1, 2016 18:17
-
-
Save shepmaster/32016491cad10a22f1e0f826d26ca07d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Meal { | |
TvDinner, | |
HomeCooked { healthy: bool }, | |
} | |
let lunch = Meal::TvDinner; | |
let dinner = Meal::HomeCooked { healthy: true }; | |
match lunch { | |
Meal::TvDinner => println!("Eating a TV dinner"), | |
Meal::HomeCooked { healthy } => { | |
if healthy { | |
println!("Eating a healthy home-cooked meal"); | |
} else { | |
println!("Eating a non-healthy home-cooked meal"); | |
} | |
}, | |
} | |
match lunch { | |
Meal::TvDinner => println!("Eating a TV dinner"), | |
Meal::HomeCooked { healthy } if healthy => println!("Eating a healthy home-cooked meal"), | |
_ => println!("Eating a non-healthy home-cooked meal"), | |
} | |
match lunch { | |
Meal::TvDinner => println!("Eating a TV dinner"), | |
Meal::HomeCooked { healthy: true } => println!("Eating a healthy home-cooked meal"), | |
Meal::HomeCooked { healthy: false } => println!("Eating a non-healthy home-cooked meal"), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment