How to swap the elements of an array, slice, or Vec?
There’s a swap method on slices: data.swap(i, j). The original code doesn’t work because the language requires that &muts do not alias, that is, if a piece of data is accessible via an &mut, then there must be no other way to use that data. In general, for successive indexes data[i], data[j], the compiler cannot … Read more