Struct MultiZip

struct MultiZip<T> { ... }

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

Implementations

impl<A> IndexedParallelIterator for MultiZip<(A)>

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

impl<A> ParallelIterator for MultiZip<(A)>

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

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

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

impl<A, B> ParallelIterator for MultiZip<(A, B)>

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

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

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

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

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

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

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

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

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

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

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

impl<A, B, C, D, E> ParallelIterator for MultiZip<(A, B, C, D, E)>

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

impl<A, B, C, D, E, F> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F)>

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

impl<A, B, C, D, E, F> ParallelIterator for MultiZip<(A, B, C, D, E, F)>

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

impl<A, B, C, D, E, F, G> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F, G)>

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

impl<A, B, C, D, E, F, G> ParallelIterator for MultiZip<(A, B, C, D, E, F, G)>

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

impl<A, B, C, D, E, F, G, H> IndexedParallelIterator for MultiZip<(A, B, C, D, E, F, G, H)>

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

impl<A, B, C, D, E, F, G, H> ParallelIterator for MultiZip<(A, B, C, D, E, F, G, H)>

fn drive_unindexed<CONSUMER>(self: Self, consumer: CONSUMER) -> <CONSUMER as >::Result
where
    CONSUMER: UnindexedConsumer<<Self as >::Item>
fn opt_len(self: &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)>

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

impl<A, B, C, D, E, F, G, H, I> ParallelIterator for MultiZip<(A, B, C, D, E, F, G, H, I)>

fn drive_unindexed<CONSUMER>(self: Self, consumer: CONSUMER) -> <CONSUMER as >::Result
where
    CONSUMER: UnindexedConsumer<<Self as >::Item>
fn opt_len(self: &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)>

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

fn drive_unindexed<CONSUMER>(self: Self, consumer: CONSUMER) -> <CONSUMER as >::Result
where
    CONSUMER: UnindexedConsumer<<Self as >::Item>
fn opt_len(self: &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)>

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

fn drive_unindexed<CONSUMER>(self: Self, consumer: CONSUMER) -> <CONSUMER as >::Result
where
    CONSUMER: UnindexedConsumer<<Self as >::Item>
fn opt_len(self: &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)>

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

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

impl<T> Any for MultiZip<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for MultiZip<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for MultiZip<T>

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

impl<T> CloneToUninit for MultiZip<T>

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

impl<T> Freeze for MultiZip<T>

impl<T> From for MultiZip<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> IntoParallelIterator for MultiZip<T>

fn into_par_iter(self: Self) -> T

impl<T> Pointable for MultiZip<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> RefUnwindSafe for MultiZip<T>

impl<T> Send for MultiZip<T>

impl<T> Sync for MultiZip<T>

impl<T> ToOwned for MultiZip<T>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> Unpin for MultiZip<T>

impl<T> UnsafeUnpin for MultiZip<T>

impl<T> UnwindSafe for MultiZip<T>

impl<T, U> Into for MultiZip<T>

fn into(self: 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 for MultiZip<T>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for MultiZip<T>

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

impl<T: $crate::clone::Clone> Clone for MultiZip<T>

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

impl<T: $crate::fmt::Debug> Debug for MultiZip<T>

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