Isn't it a little strange that tuple can be partly moved, while array cannot

suppose we have a non-copy type

struct Foo{
    x:i32,
}

This works:

let a=(Foo{x:4},Foo{x:4});
let b=a.0;

And this does not:

let a=[Foo{x:4},Foo{x:4}];
let b=a[0];

You can do it with pattern;

let [b,_] = a;

More coming.

1 Like

There's a big difference here in that a[0] works via std::ops::Index, but a.0 does not. So the array indexing calls into user code, while the tuple indexing does not.

1 Like

Tuple indices are always constant, array indices are generally not. The compiler cannot reason about the two equally, even if the already-mentioned implications of Index were not there.

2 Likes