pub struct Parallel<'a, T> { /* private fields */ }
Expand description

A builder that runs closures in parallel.

Implementations

Creates a builder for running closures in parallel.

Examples
use easy_parallel::Parallel;

let p = Parallel::<()>::new();

Adds a closure to the list.

Examples
use easy_parallel::Parallel;

Parallel::new()
    .add(|| println!("hello from a thread"))
    .run();

Adds a cloned closure for each item in an iterator.

Each clone of the closure takes an item as an argument.

Examples
use easy_parallel::Parallel;

Parallel::new()
    .each(0..5, |i| println!("hello from thread #{}", i))
    .run();

Runs each closure on a separate thread and collects their results.

Results are collected in the order in which closures were added. One of the closures always runs on the main thread because there is no point in spawning an extra thread for it.

If a closure panics, panicking will resume in the main thread after all threads are joined.

Examples
use easy_parallel::Parallel;
use std::thread;
use std::time::Duration;

let res = Parallel::new()
    .each(1..=3, |i| 10 * i)
    .add(|| 100)
    .run();

assert_eq!(res, [10, 20, 30, 100]);

Finishes with a closure to run on the main thread, starts threads, and collects results.

Results are collected in the order in which closures were added.

If a closure panics, panicking will resume in the main thread after all threads are joined.

Examples
use easy_parallel::Parallel;
use std::thread;
use std::time::Duration;

let (res, ()) = Parallel::new()
    .each(1..=3, |i| 10 * i)
    .finish(|| println!("Waiting for results"));

assert_eq!(res, [10, 20, 30]);

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.