https://github.com/finnbear/maybe_parallel_iterator
Toggle parallelism with feature flags!
https://github.com/finnbear/maybe_parallel_iterator
crate parallel parallelism rayon rust rust-crate rust-lang
Last synced: 12 months ago
JSON representation
Toggle parallelism with feature flags!
- Host: GitHub
- URL: https://github.com/finnbear/maybe_parallel_iterator
- Owner: finnbear
- License: mit
- Created: 2022-05-27T02:10:36.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-27T02:47:48.000Z (over 3 years ago)
- Last Synced: 2025-03-16T17:12:50.632Z (12 months ago)
- Topics: crate, parallel, parallelism, rayon, rust, rust-crate, rust-lang
- Language: Rust
- Homepage: https://crates.io/crates/maybe_parallel_iterator
- Size: 16.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# maybe_parallel_iterator
Write your code once. Then toggle between sequential and parallel iterators with a feature flag!
```rust
let a: Vec = (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](https://github.com/rayon-rs/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
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
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.