Foo(&mut d[i1], &mut d[i2]); // for i1 != i2

foo(&mut d[i1], &mut d[i2]); // for i1 != i2

Is it possible to do the above, for situations we are absoluteyl certain i1 != i2 ?

You can do it safely with some sequence of split_at_mut, split_first_mut, etc.

Or if these are Copy elements, consider the approach in this article.

Otherwise you need unsafe and may need to use *mut too.

3 Likes

On the off chance you're using nightly already, there is also slice::get_many_mut.

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.