Skip to content

Instantly share code, notes, and snippets.

@mizchi
Last active September 24, 2023 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/34efb18865a1894d844964ece42dca33 to your computer and use it in GitHub Desktop.
Save mizchi/34efb18865a1894d844964ece42dca33 to your computer and use it in GitHub Desktop.
fn main() {
let x: Option<Result<(&str, &str), ()>> = Some(Ok(("x", "y")));
// if let
if let Some(Ok((a, _))) = x {
if a == "x" {
println!("a=x");
}
}
// match
match x {
Some(Ok((a, _))) => {
if a == "x" {
println!("a=x");
}
}
_ => {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment