I was thinking how const array slices could be
concated together (See playground), and I found it possible only to merge whole const arrays. But I'd also, as an owner of a
[T;N] would like to get an owned "slice"
1 <= M <= N and throw away all the
N-M array positions that I don't care about. I believe this could allow the use case of concating arbitrary slices of const arrays.
So the following should be valid:
let x: [u32; 3] = [1,2,3]; let y: [u32;2] = x[0..=1];
x becomes a partially moved value.
Currently there is an error (first that
y's type is invalid) and second that y doesn't have a size known at compile time!!! Which is not true! We know
y's length and
y's inner type, and we become the owners of the array.
T is not
of course the following should be invalid and throw an error at compile time (thanks @SkiFire13):
let x: [String; 4] = ["hello".into(), "there".into(), "General".into(), "Kenobi".into()]; let y: [String; 2] = x[0..=1]; x; x;