Trait slicetools::SliceTools
[−]
[src]
pub trait SliceTools { fn cartesian_product_mut<'a, S, T: 'a, U: 'a>(
&'a mut self,
slice: &'a mut S
) -> CartesianProductMut<'a, T, U>
where
Self: AsMut<[T]>,
S: AsMut<[U]>, { ... } fn pairs_mut<'a, T: 'a>(&'a mut self) -> PairsMut<'a, T>
where
Self: AsMut<[T]>, { ... } }
A trait to extend slices and Vec
s with streaming iterators.
Provided Methods
fn cartesian_product_mut<'a, S, T: 'a, U: 'a>(
&'a mut self,
slice: &'a mut S
) -> CartesianProductMut<'a, T, U> where
Self: AsMut<[T]>,
S: AsMut<[U]>,
&'a mut self,
slice: &'a mut S
) -> CartesianProductMut<'a, T, U> where
Self: AsMut<[T]>,
S: AsMut<[U]>,
Iterate on all the pairs (a, b) from slices A and B such as a ∈ A and b ∈ B, yielding mutables references on items.
Example
use slicetools::*; let mut v1 = vec![100; 3]; let mut v2 = vec![1, 2, 3, 4]; { let mut it = v1.cartesian_product_mut(&mut v2); while let Some((a, b)) = it.next() { *a += *b; } } assert_eq!(v1, &[110; 3]);
fn pairs_mut<'a, T: 'a>(&'a mut self) -> PairsMut<'a, T> where
Self: AsMut<[T]>,
Self: AsMut<[T]>,
Iterate on all the possible pairs of the slice, yielding mutables references on items.
Example
use slicetools::*; let mut v = vec![1, 2, 3, 4]; { let mut it = v.pairs_mut(); while let Some((a, b)) = it.next() { if *b > *a { *a += 1; } } } assert_eq!(v, &[4, 4, 4, 4]);
Implementors
impl<T> SliceTools for T