How do slice patterns work?

This works:

let a = &caps[1];
let b = &caps[2];
let c = &caps[3];
let d = &caps[4];
let e = &caps[5];

(Those are captures from Regex::captures().)

This doesn't:

let [_, a, b, c, d, e] = ∩︀

The error is

expected an array or slice, found `regex::re_unicode::Captures<'_>`

I thought this is how slice patterns work. What am I missing?

Sure, but &caps is not a slice. It's a Captures that just happens to implement the Index trait.

4 Likes