Skip to content

Instantly share code, notes, and snippets.

@Shaun289
Created November 8, 2021 00:39
Show Gist options
  • Save Shaun289/244bd3993ca806473c690a4a98b6caf8 to your computer and use it in GitHub Desktop.
Save Shaun289/244bd3993ca806473c690a4a98b6caf8 to your computer and use it in GitHub Desktop.
Rust study : if let
/*
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