If...Let Expression
let mut arr1:[i64 ; 3] = [1,2,3];
if let[1,2,_] = arr1{
println!("Works with array");
}
let mut arr2:[&str; 2] = ["one", "two"];
if let["Apple", _] = arr2{
println!("Works with str array too");
}
let tuple\_1 = ("India", 7, 90, 90.432);
if let(_, 7, 9, 78.99) = tuple_1{
println!("Works with tuples too");
}
let tuple\_2 = ( 9, 7, 89, 12, "Okay");
if let(9, 7,89, 12, blank) = tuple_2 {
println!("Everything {blank} mate?");
}
let tuple\_3 = (89, 90, "Yes");
if let(9, 89, "Yes") = tuple_3{
println!("Pattern did match");
}
else {
println!("Pattern did not match");
}
Comments