if let Some
📝 Rustif let Some in Rust is a concise pattern for matching the Some variant of an Option, executing code only when the value is present and binding the inner value.
Rust
fn main() { let value: Option<i32> = Some(42); if let Some(x) = value { println!("Got {}", x); }
}
Comments
if let Some(x) is fine until you need to also handle the None case and realize you should have just used match.