-
-
Save vijairaj/7852fb9fb025a58f8d73119f8f20b5b4 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains 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
fn print(n: Option<i32>) { | |
// conditionally destructure | |
if let Some(inner) = n { | |
println!("Val: {}", inner); | |
} | |
} | |
fn main() { | |
print(None); | |
print(Some(0)); | |
print(Some(5)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if let
syntax is confusing at first but the core idea is that it's conditionallet
.In the example
inner
is assigned only whenn
is notNone