enum_example: Add if let example
This commit is contained in:
parent
c2cb93c15f
commit
47599b6c7e
1 changed files with 12 additions and 0 deletions
|
|
@ -53,4 +53,16 @@ fn main() {
|
||||||
let msg = Message::YetAnotherMessage;
|
let msg = Message::YetAnotherMessage;
|
||||||
msg.print();
|
msg.print();
|
||||||
msg.call();
|
msg.call();
|
||||||
|
|
||||||
|
let some_u8_value = Some(8);
|
||||||
|
|
||||||
|
if let Some(8) = some_u8_value {
|
||||||
|
println!("Some is 8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(9) = some_u8_value {
|
||||||
|
println!("BAD: Some is not 9, why am I here?");
|
||||||
|
} else {
|
||||||
|
println!("Correct: Some is not 9, so we should else");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue