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,
size: usize
) -> RChunksMutIter<'a, Self::Item>; }
The RChunks
trait.
This trait provides two methods on slices: rchunks and rchunks_mut. Both take a usize as input for the chunk size, see the method documentations for exact behavior and usage.
Associated Types
type Item
This type is the type of the contents of the underlying slice: Item = T for [T].
Required Methods
fn rchunks<'a>(&'a self, size: usize) -> RChunksIter<'a, Self::Item>
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());
fn rchunks_mut<'a>(&'a mut self, size: usize) -> RChunksMutIter<'a, Self::Item>
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])