if let
Running code only if a value matches one pattern.
if let PATTERN = expr runs its block when the pattern matches; let chains join several conditions with &&.
Examples
if let Some(first) = names.first() { println!("{first}"); }runs only when the list is not empty.In edition 2024,
if let Some(n) = age && n >= 18 { ... }joins a pattern and a condition with&&.
See also