Created
November 8, 2021 00:39
-
-
Save Shaun289/244bd3993ca806473c690a4a98b6caf8 to your computer and use it in GitHub Desktop.
Rust study : if let
This file contains hidden or 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
/* | |
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/flow_control/if_let.html | |
compiled on https://play.rust-lang.org/ | |
result : | |
Matched 7! | |
Not matched : letter | |
emoticon is None! | |
*/ | |
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!("Not matched : letter") | |
} | |
if emoticon == None { | |
println!("emoticon is None!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment