[][src]Trait rayon::prelude::ParallelBridge

pub trait ParallelBridge: Sized {
    fn par_bridge(self) -> IterBridge<Self>;

Conversion trait to convert an Iterator to a ParallelIterator.

This creates a "bridge" from a sequential iterator to a parallel one, by distributing its items across the Rayon thread pool. This has the advantage of being able to parallelize just about anything, but the resulting ParallelIterator can be less efficient than if you started with par_iter instead. However, it can still be useful for iterators that are difficult to parallelize by other means, like channels or file or network I/O.

The resulting iterator is not guaranteed to keep the order of the original iterator.


To use this trait, take an existing Iterator and call par_bridge on it. After that, you can use any of the ParallelIterator methods:

use rayon::iter::ParallelBridge;
use rayon::prelude::ParallelIterator;
use std::sync::mpsc::channel;

let rx = {
    let (tx, rx) = channel();



let mut output: Vec<&'static str> = rx.into_iter().par_bridge().collect();

assert_eq!(&*output, &["one!", "three!", "two!"]);

Required methods

fn par_bridge(self) -> IterBridge<Self>

Creates a bridge from this type to a ParallelIterator.

Loading content...


impl<T: Iterator + Send> ParallelBridge for T where
    T::Item: Send

Loading content...