#parallel-iterator #toggle #flags #parallelism #sequential #features #rayon

maybe_parallel_iterator

Toggle parallelism with feature flags!

10 breaking releases

0.12.0 Jun 27, 2022
0.10.0 May 27, 2022

#9 in #feature

Download history 468/week @ 2024-08-03 404/week @ 2024-08-10 234/week @ 2024-08-17 201/week @ 2024-08-24 389/week @ 2024-08-31 1132/week @ 2024-09-07 1052/week @ 2024-09-14 675/week @ 2024-09-21 595/week @ 2024-09-28 222/week @ 2024-10-05 310/week @ 2024-10-12 472/week @ 2024-10-19 285/week @ 2024-10-26 454/week @ 2024-11-02 435/week @ 2024-11-09 302/week @ 2024-11-16

1,582 downloads per month
Used in 4 crates (via voronator)

MIT/Apache

17KB
363 lines

maybe_parallel_iterator

Write your code once. Then toggle between sequential and parallel iterators with a feature flag!

let a: Vec<i32> = (0..100).collect();
a.into_maybe_parallel_iterator()
    .with_min_sequential(2)
    .map(|n| -n)
    .enumerate()
    .flat_map(|(e, n)| vec![e as i32, n, n + 1000].into_maybe_parallel_iterator())
    .for_each(|item| {
        println!("par: {:?}", item);
    })

Features

  • Iterators
    • into_maybe_par_iter
    • maybe_par_iter
    • maybe_par_iter_mut
  • Sorts
    • maybe_par_sort
    • maybe_par_sort_unstable
    • maybe_par_sort_by
    • maybe_par_sort_unstable_by
    • maybe_par_sort_by_key
    • maybe_par_sort_unstable_by_key

Use the rayon feature flag to enable rayon parallelism.

The default is sequential ("rayoff" mode).

Limitations

For now, only supports these iterator adapters:

  • collect
  • *enumerate
  • filter_map
  • find_any
  • flat_map
  • for_each
  • map
  • *with_min_sequential (no-op unless rayon feature enabled)

*Only available for IndexedParallelIterator's if rayon feature enabled.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0–265KB