Trait rchunks::RChunks [] [src]

pub trait RChunks {
    type Item;
    fn rchunks<'a>(&'a self, size: usize) -> RChunksIter<'a, Self::Item>;
fn rchunks_mut<'a>(
        &'a mut self,
        csize: usize
    ) -> RChunksMutIter<'a, Self::Item>; }

Associated Types

Required Methods

Returns an iterator over size elements of the slice at a time, starting from the end of the slice and working backwards. The chunks are slices and do not overlap. if size does not evenly divide the length of the slice, then the final chunk produced by this iterator will have a length less than size.

Panic

Panics if size is 0.

Example

use rchunks::RChunks;

let slice = &['d', 'a', 'n', 'k', 'm', 'e', 'm', 'e'];
let mut iter = slice.rchunks(3);
assert_eq!(iter.next().unwrap(), &['e', 'm', 'e']);
assert_eq!(iter.next().unwrap(), &['n', 'k', 'm']);
assert_eq!(iter.next().unwrap(), &['d', 'a']);
assert!(iter.next().is_none());

Returns an iterator over size elements of the slice at a time, starting from the end of the slice and working backwards. The chunks are mutable slices and do not overlap. if size does not evenly divide the length of the slice, then the final chunk produced by this iterator will have a length less than size.

Panic

Panics if size is 0.

Example

use rchunks::RChunks;

let slice = &mut [0;10];
{
let mut iter = slice.rchunks_mut(3);
let mut counter = 0;
for chunk in iter {
    for elem in chunk {
        *elem = counter;
    }
    counter += 1;    
}
}
assert_eq!(slice, &[3, 2, 2, 2, 1, 1, 1, 0, 0, 0])

Implementors