[][src]Function moveslice::moveslice

pub fn moveslice<T>(slice: &mut [T], chunk: (usize, usize), destination: usize)

Moves a slice around in an array. Works by splitting and rotating.

There are three parameters:

  • slice : The slice to modify.
  • chunk : A tuple with the boundaries of the chunk you want to move.
  • destination : Where you want to move the chunk.

Note that the destination specifies where the first element of the chunk will be. As a result, its maximum value is not the length of the slice.

For example, if you have a slice with size 10, and you're moving a chunk of size 3 around, the maximum value for the destination is 10-3= 7.

Panics

Panics when the destination leads the chunk out of bounds.

In the example above, if I specify a destination of 8, the function will panic, showing what would be the placement of the chunk, and the length of the slice.

let mut arr = [1,2,3,4,5,6,7,8,9];
let result = moveslice(&mut arr, (3,6), 7); // will panic