Struct MultiZip

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

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<A> IndexedParallelIterator for MultiZip<(A,)> where A: IndexedParallelIterator,

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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

type Item = (<A as ParallelIterator>::Item,);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item, <D as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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,

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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,

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item, <D as ParallelIterator>::Item, <E as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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,

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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,

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item, <D as ParallelIterator>::Item, <E as ParallelIterator>::Item, <F as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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,

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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,

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item, <D as ParallelIterator>::Item, <E as ParallelIterator>::Item, <F as ParallelIterator>::Item, <G as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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,

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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,

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item, <D as ParallelIterator>::Item, <E as ParallelIterator>::Item, <F as ParallelIterator>::Item, <G as ParallelIterator>::Item, <H as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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,

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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,

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item, <D as ParallelIterator>::Item, <E as ParallelIterator>::Item, <F as ParallelIterator>::Item, <G as ParallelIterator>::Item, <H as ParallelIterator>::Item, <I as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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,

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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,

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item, <D as ParallelIterator>::Item, <E as ParallelIterator>::Item, <F as ParallelIterator>::Item, <G as ParallelIterator>::Item, <H as ParallelIterator>::Item, <I as ParallelIterator>::Item, <J as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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,

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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,

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item, <D as ParallelIterator>::Item, <E as ParallelIterator>::Item, <F as ParallelIterator>::Item, <G as ParallelIterator>::Item, <H as ParallelIterator>::Item, <I as ParallelIterator>::Item, <J as ParallelIterator>::Item, <K as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

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,

fn drive<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: Consumer<Self::Item>,
fn len(&self) -> usize
fn with_producer<CB>(self, callback: CB) -> CB::Output
where
    CB: ProducerCallback<Self::Item>,

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,

type Item = (<A as ParallelIterator>::Item, <B as ParallelIterator>::Item, <C as ParallelIterator>::Item, <D as ParallelIterator>::Item, <E as ParallelIterator>::Item, <F as ParallelIterator>::Item, <G as ParallelIterator>::Item, <H as ParallelIterator>::Item, <I as ParallelIterator>::Item, <J as ParallelIterator>::Item, <K as ParallelIterator>::Item, <L as ParallelIterator>::Item);
fn drive_unindexed<CONSUMER>(self, consumer: CONSUMER) -> CONSUMER::Result
where
    CONSUMER: UnindexedConsumer<Self::Item>,
fn opt_len(&self) -> Option<usize>

impl<T: Clone> Clone for MultiZip<T>

fn clone(&self) -> MultiZip<T>

impl<T: Debug> Debug for MultiZip<T>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl<T> Freeze for MultiZip<T> where T: Freeze,

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> UnsafeUnpin for MultiZip<T> where T: UnsafeUnpin,

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

Blanket Implementations

impl<T> Any for MultiZip<T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for MultiZip<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for MultiZip<T> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for MultiZip<T> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for MultiZip<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> IntoEither for MultiZip<T>

impl<T> IntoParallelIterator for MultiZip<T> where T: ParallelIterator,

type Iter = T;
type Item = <T as ParallelIterator>::Item;
fn into_par_iter(self) -> T

impl<T> Pointable for MultiZip<T>

const ALIGN: usize = _;
type Init = T;
unsafe fn init(init: <T as Pointable>::Init) -> usize
unsafe fn deref<'a>(ptr: usize) -> &'a T
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
unsafe fn drop(ptr: usize)

impl<T> ToOwned for MultiZip<T> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for MultiZip<T> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for MultiZip<T> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for MultiZip<T> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>