Sha256: afa4b04ba6ea1d37aed2d68eca44d7ba0d1d09ea985c9091540dd8d3c51974f1

Contents?: true

Size: 1.86 KB

Versions: 38

Compression:

Stored size: 1.86 KB

Contents

use crate::iter::plumbing::*;
use crate::iter::Either::{Left, Right};
use crate::iter::*;

/// `Either<L, R>` is a parallel iterator if both `L` and `R` are parallel iterators.
impl<L, R> ParallelIterator for Either<L, R>
where
    L: ParallelIterator,
    R: ParallelIterator<Item = L::Item>,
{
    type Item = L::Item;

    fn drive_unindexed<C>(self, consumer: C) -> C::Result
    where
        C: UnindexedConsumer<Self::Item>,
    {
        match self {
            Left(iter) => iter.drive_unindexed(consumer),
            Right(iter) => iter.drive_unindexed(consumer),
        }
    }

    fn opt_len(&self) -> Option<usize> {
        self.as_ref().either(L::opt_len, R::opt_len)
    }
}

impl<L, R> IndexedParallelIterator for Either<L, R>
where
    L: IndexedParallelIterator,
    R: IndexedParallelIterator<Item = L::Item>,
{
    fn drive<C>(self, consumer: C) -> C::Result
    where
        C: Consumer<Self::Item>,
    {
        match self {
            Left(iter) => iter.drive(consumer),
            Right(iter) => iter.drive(consumer),
        }
    }

    fn len(&self) -> usize {
        self.as_ref().either(L::len, R::len)
    }

    fn with_producer<CB>(self, callback: CB) -> CB::Output
    where
        CB: ProducerCallback<Self::Item>,
    {
        match self {
            Left(iter) => iter.with_producer(callback),
            Right(iter) => iter.with_producer(callback),
        }
    }
}

/// `Either<L, R>` can be extended if both `L` and `R` are parallel extendable.
impl<L, R, T> ParallelExtend<T> for Either<L, R>
where
    L: ParallelExtend<T>,
    R: ParallelExtend<T>,
    T: Send,
{
    fn par_extend<I>(&mut self, par_iter: I)
    where
        I: IntoParallelIterator<Item = T>,
    {
        match self.as_mut() {
            Left(collection) => collection.par_extend(par_iter),
            Right(collection) => collection.par_extend(par_iter),
        }
    }
}

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/rayon-1.10.0/src/par_either.rs
wasmtime-28.0.0 ./ext/cargo-vendor/rayon-1.10.0/src/par_either.rs
wasmtime-27.0.0 ./ext/cargo-vendor/rayon-1.10.0/src/par_either.rs
wasmtime-26.0.0 ./ext/cargo-vendor/rayon-1.10.0/src/par_either.rs
wasmtime-25.0.2 ./ext/cargo-vendor/rayon-1.10.0/src/par_either.rs
wasmtime-25.0.1 ./ext/cargo-vendor/rayon-1.10.0/src/par_either.rs
wasmtime-25.0.0 ./ext/cargo-vendor/rayon-1.10.0/src/par_either.rs
wasmtime-24.0.0 ./ext/cargo-vendor/rayon-1.10.0/src/par_either.rs
wasmtime-23.0.2 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-22.0.0 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-21.0.1 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-20.0.2 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-20.0.0 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-18.0.3 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-17.0.1 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-17.0.0 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-16.0.0 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-15.0.1 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-15.0.0 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs
wasmtime-14.0.4 ./ext/cargo-vendor/rayon-1.8.0/src/par_either.rs