parallel_stream/lib.rs
1//! Data parallelism library for async-std.
2//!
3//! This library provides convenient parallel iteration of
4//! [`Streams`](https://docs.rs/futures-core). Analogous to how
5//! [Rayon](https://docs.rs/rayon/) provides parallel iteration of
6//! `Iterator`s. This allows processing data coming from a stream in parallel,
7//! enabling use of *all* system resources.
8//!
9//! You can read about the design decisions and motivation in the "parallel
10//! streams" section of the ["streams
11//! concurrency"](https://blog.yoshuawuyts.com/streams-concurrency/#parallel-streams)
12//! blog post.
13//!
14//! # Differences with Rayon
15//!
16//! Rayon is a data parallelism library built for synchronous Rust, powered by
17//! an underlying thread pool. async-std manages a thread pool as well, but the
18//! key difference with Rayon is that async-std (and futures) are optimized for
19//! *latency*, while Rayon is optimized for *throughput*.
20//!
21//! As a rule of thumb: if you want to speed up doing heavy calculations you
22//! probably want to use Rayon. If you want to parallelize network requests
23//! consider using `parallel-stream`.
24//!
25//! # Examples
26//!
27//! ```
28//! use parallel_stream::prelude::*;
29//!
30//! #[async_std::main]
31//! async fn main() {
32//! let v = vec![1, 2, 3, 4];
33//! let mut out: Vec<usize> = v
34//! .into_par_stream()
35//! .map(|n| async move { n * n })
36//! .collect()
37//! .await;
38//! out.sort();
39//! assert_eq!(out, vec![1, 4, 9, 16]);
40//! }
41//! ```
42
43#![forbid(unsafe_code)]
44#![deny(missing_debug_implementations, nonstandard_style)]
45#![warn(missing_docs)]
46
47mod from_parallel_stream;
48mod from_stream;
49mod into_parallel_stream;
50mod par_stream;
51
52pub use from_parallel_stream::FromParallelStream;
53pub use from_stream::{from_stream, FromStream};
54pub use into_parallel_stream::IntoParallelStream;
55pub use par_stream::{ForEach, Map, NextFuture, ParallelStream, Take};
56
57pub mod prelude;
58pub mod vec;
59
60pub(crate) mod utils;