moveslice
This crate contains a single function moveslice
. Its purpose
is to move a chunk within a slice around. It only uses safe functions,
and acts efficiently by using the
split_at_mut
and
rotate_left
/
rotate_right
functions.
Examples:
use moveslice;
let mut arr = ;
// The following moves the slice 3..6 to index 1.
// In effect, it moves [4,5,6] over to where [2] is.
moveslice;
assert_eq!;
// The following moves the slice 3..6 to index 6.
// In effect, it moves [6,2,3] over to where [7] is.
moveslice;
assert_eq!;
// The following attempts to move the slice beyond boundaries.
// The index given is 7, which exists in the array, but the
// last element of the chunk will not fit (7 + 3 = 10 > 9).
// Therefore, the following should fail.
let result = moveslice;
// You could pass the destination as the same value as chunk.0.
// However this would mean nothing is moved.
// Since it's not technically an error however, only a warning is logged.
moveslice;