I have a Rust [i32; 6] that I'd like to split into three [i32; 2]. Can this be done by pattern matching, or do I explicitly have to reference all six elements?
I'd like to do something like this:
let arr6 = [0, 1, 2, 3, 4, 5];
let [sub1 @ [_; 2], sub2 @ [_; 2], sub3 @ [_; 2]] = arr6;
// or
let [sub1 @ [_, _], sub2 @ [_, _], sub3 @ [_, _]] = arr6;
Currently the only solution I see is
let sub1 = [arr6[0], arr6[1]];
let sub2 = [arr6[2], arr6[3]];
let sub3 = [arr6[3], arr6[4]]; // <-- whoops, that's wrong
as_chunksmethod. I think the closest thing that the stable standard library provides would be to iterate (and collect?) viachunks_exact, though of course (withunsafe) you could also reimplement the unstable API yourself.