Destructuring Arrays
- Destructuring of slices of unknown length also works with patterns of fixed length.
inspect(&[0, -2, 3]);
inspect(&[0, -2, 3, 4]);
fn inspect(slice: &[i32]) {
println!("Tell me about {slice:?}");
&[0, y, z] => println!("First is 0, y = {y}, and z = {z}"),
_ => println!("All elements were ignored"),
}
- Show matching against the tail with patterns
[.., b]
and