Some if-let in RBE
This commit is contained in:
25
rustbyexample/flow_control.d/if_let.rs
Normal file
25
rustbyexample/flow_control.d/if_let.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
fn main() {
|
||||
let number = Some(7);
|
||||
let letter: Option<i32> = None;
|
||||
let emoticon: Option<i32> = None;
|
||||
|
||||
if let Some(i) = number {
|
||||
println!("Matched {:?}!", i);
|
||||
}
|
||||
|
||||
if let Some(i) = letter {
|
||||
println!("Matched {:?}!", i);
|
||||
} else {
|
||||
println!("Didn't match a number. Let's go with a letter!");
|
||||
}
|
||||
|
||||
let i_like_letters = false;
|
||||
|
||||
if let Some(i) = emoticon {
|
||||
println!("Matched {:?}!", i);
|
||||
} else if i_like_letters {
|
||||
println!("Didn't match a number. Let's go with a letter!");
|
||||
} else {
|
||||
println!("I don't like letters. Let's go with an emoticon :)!");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user