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 Vecs with streaming iterators.

Provided Methods

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]);

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