Skip to content

Instantly share code, notes, and snippets.

@shepmaster
Created July 1, 2016 18:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shepmaster/32016491cad10a22f1e0f826d26ca07d to your computer and use it in GitHub Desktop.
Save shepmaster/32016491cad10a22f1e0f826d26ca07d to your computer and use it in GitHub Desktop.
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