Divide slices into portions of same size
Divide_slice provides two additional methods to the primitive type slice:
divide: divide a slice intonnon-overlapping portions, returning an iterator.divide_mut: divide a slice intonmutable non-overlapping portions, returning an iterator.
Difference with slice::chunks
The standard library provides the methods chunks and chunks_mut, which return a (mutable) iterator over a given number of elements of a slice at the same time.
The difference between chunks and divide is that you determine the size of the chunks with chunks, and the number of subslices you want with divide:
let slice = ;
let mut iter = slice.chunks;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let mut iter = slice.divide;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Divide is more appropriate when you want to split the work equally among different threads.