Struct rayon::iter::MultiZip[][src]

pub struct MultiZip<T> { /* fields omitted */ }

MultiZip is an iterator that zips up a tuple of parallel iterators to produce tuples of their items.

It is created by calling into_par_iter() on a tuple of types that implement IntoParallelIterator, or par_iter()/par_iter_mut() with types that are iterable by reference.

The implementation currently support tuples up to length 12.

Examples

use rayon::prelude::*;

// This will iterate `r` by mutable reference, like `par_iter_mut()`, while
// ranges are all iterated by value like `into_par_iter()`.
// Note that the zipped iterator is only as long as the shortest input.
let mut r = vec![0; 3];
(&mut r, 1..10, 10..100, 100..1000).into_par_iter()
    .for_each(|(r, x, y, z)| *r = x * y + z);

assert_eq!(&r, &[1 * 10 + 100, 2 * 11 + 101, 3 * 12 + 102]);

For a group that should all be iterated by reference, you can use a tuple reference.

use rayon::prelude::*;

let xs: Vec<_> = (1..10).collect();
let ys: Vec<_> = (10..100).collect();
let zs: Vec<_> = (100..1000).collect();

// Reference each input separately with `IntoParallelIterator`:
let r1: Vec<_> = (&xs, &ys, &zs).into_par_iter()
    .map(|(x, y, z)| x * y + z)
    .collect();

// Reference them all together with `IntoParallelRefIterator`:
let r2: Vec<_> = (xs, ys, zs).par_iter()
    .map(|(x, y, z)| x * y + z)
    .collect();

assert_eq!(r1, r2);

Mutable references to a tuple will work similarly.

use rayon::prelude::*;

let mut xs: Vec<_> = (1..4).collect();
let mut ys: Vec<_> = (-4..-1).collect();
let mut zs = vec![0; 3];

// Mutably reference each input separately with `IntoParallelIterator`:
(&mut xs, &mut ys, &mut zs).into_par_iter().for_each(|(x, y, z)| {
    *z += *x + *y;
    std::mem::swap(x, y);
});

assert_eq!(xs, (vec![-4, -3, -2]));
assert_eq!(ys, (vec![1, 2, 3]));
assert_eq!(zs, (vec![-3, -1, 1]));

// Mutably reference them all together with `IntoParallelRefMutIterator`:
let mut tuple = (xs, ys, zs);
tuple.par_iter_mut().for_each(|(x, y, z)| {
    *z += *x + *y;
    std::mem::swap(x, y);
});

assert_eq!(tuple, (vec![1, 2, 3], vec![-4, -3, -2], vec![-6, -2, 2]));

Trait Implementations

impl<T: Clone> Clone for MultiZip<T>[src]

impl<T: Debug> Debug for MultiZip<T>[src]

impl<A> IndexedParallelIterator for MultiZip<(A,)> where
    A: IndexedParallelIterator
[src]

impl<A, B> IndexedParallelIterator for MultiZip<(A, B)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator
[src]

impl<A, B, C, D, E, F, G, H, I, J, K> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F, G, H, I, J, K)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator,
    I: IndexedParallelIterator,
    J: IndexedParallelIterator,
    K: IndexedParallelIterator
[src]

impl<A, B, C, D, E, F, G, H, I, J, K, L> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F, G, H, I, J, K, L)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator,
    I: IndexedParallelIterator,
    J: IndexedParallelIterator,
    K: IndexedParallelIterator,
    L: IndexedParallelIterator
[src]

impl<A, B, C> IndexedParallelIterator for MultiZip<(A, B, C)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator
[src]

impl<A, B, C, D> IndexedParallelIterator for MultiZip<(A, B, C, D)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator
[src]

impl<A, B, C, D, E> IndexedParallelIterator for MultiZip<(A, B, C, D, E)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator
[src]

impl<A, B, C, D, E, F> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator
[src]

impl<A, B, C, D, E, F, G> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F, G)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator
[src]

impl<A, B, C, D, E, F, G, H> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F, G, H)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator
[src]

impl<A, B, C, D, E, F, G, H, I> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F, G, H, I)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator,
    I: IndexedParallelIterator
[src]

impl<A, B, C, D, E, F, G, H, I, J> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F, G, H, I, J)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator,
    I: IndexedParallelIterator,
    J: IndexedParallelIterator
[src]

impl<A> ParallelIterator for MultiZip<(A,)> where
    A: IndexedParallelIterator
[src]

type Item = (A::Item,)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B> ParallelIterator for MultiZip<(A, B)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C, D, E, F, G, H, I, J, K> ParallelIterator for MultiZip<(A, B, C, D, E, F, G, H, I, J, K)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator,
    I: IndexedParallelIterator,
    J: IndexedParallelIterator,
    K: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item, I::Item, J::Item, K::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C, D, E, F, G, H, I, J, K, L> ParallelIterator for MultiZip<(A, B, C, D, E, F, G, H, I, J, K, L)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator,
    I: IndexedParallelIterator,
    J: IndexedParallelIterator,
    K: IndexedParallelIterator,
    L: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item, I::Item, J::Item, K::Item, L::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C> ParallelIterator for MultiZip<(A, B, C)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C, D> ParallelIterator for MultiZip<(A, B, C, D)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item, D::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C, D, E> ParallelIterator for MultiZip<(A, B, C, D, E)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item, D::Item, E::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C, D, E, F> ParallelIterator for MultiZip<(A, B, C, D, E, F)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C, D, E, F, G> ParallelIterator for MultiZip<(A, B, C, D, E, F, G)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C, D, E, F, G, H> ParallelIterator for MultiZip<(A, B, C, D, E, F, G, H)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C, D, E, F, G, H, I> ParallelIterator for MultiZip<(A, B, C, D, E, F, G, H, I)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator,
    I: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item, I::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

impl<A, B, C, D, E, F, G, H, I, J> ParallelIterator for MultiZip<(A, B, C, D, E, F, G, H, I, J)> where
    A: IndexedParallelIterator,
    B: IndexedParallelIterator,
    C: IndexedParallelIterator,
    D: IndexedParallelIterator,
    E: IndexedParallelIterator,
    F: IndexedParallelIterator,
    G: IndexedParallelIterator,
    H: IndexedParallelIterator,
    I: IndexedParallelIterator,
    J: IndexedParallelIterator
[src]

type Item = (A::Item, B::Item, C::Item, D::Item, E::Item, F::Item, G::Item, H::Item, I::Item, J::Item)

The type of item that this parallel iterator produces. For example, if you use the for_each method, this is the type of item that your closure will be invoked with. Read more

Auto Trait Implementations

impl<T> RefUnwindSafe for MultiZip<T> where
    T: RefUnwindSafe

impl<T> Send for MultiZip<T> where
    T: Send

impl<T> Sync for MultiZip<T> where
    T: Sync

impl<T> Unpin for MultiZip<T> where
    T: Unpin

impl<T> UnwindSafe for MultiZip<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoParallelIterator for T where
    T: ParallelIterator
[src]

type Iter = T

The parallel iterator type that will be created.

type Item = <T as ParallelIterator>::Item

The type of item that the parallel iterator will produce.

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.