Pattern matching, if...let
When we use match
for pattern matching we have to care for all possible occurrences, if...let
helps us care only for what we want to care for without triggering a compile error for not addressing possible cases.
fn main(){
let my_vec = vec![2,66,8,4];
for index in 0..=5{
if let Some(number) = my_vec.get(index){
println!("Number {} is present", index)
}
}
}