maybe_parallel_iterator

Crates.iomaybe_parallel_iterator
lib.rsmaybe_parallel_iterator
version0.12.0
sourcesrc
created_at2022-05-27 04:44:49.235915
updated_at2022-06-27 02:47:52.158339
descriptionToggle parallelism with feature flags!
homepage
repositoryhttps://github.com/finnbear/maybe_parallel_iterator/
max_upload_size
id594844
size17,905
Finn Bear (finnbear)

documentation

README

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.

Commit count: 20

cargo fmt