merge_streams/
lib.rs

1//! Merge multiple streams into one.
2//!
3//! Based on Yoshua Wuyts's
4//! [`futures-concurrency`](https://docs.rs/futures-concurrency/latest)
5//! crate and the corresponding
6//! [_Futures Concurrency III_](https://blog.yoshuawuyts.com/futures-concurrency-3/)
7//! post.
8//!
9//! The main trait of this crate is [`MergeStreams`], which provides a `merge`
10//! function on tuples, arrays, and vectors of streams. The [`StreamExt`]
11//! trait provides a `Stream::merge` method to make merging two streams more
12//! convenient.
13//!
14//! # Example
15//!
16//! Merge multiple streams to handle values as soon as they're ready, without
17//! ever dropping a single value:
18//!
19//! ```
20//! use merge_streams::MergeStreams;
21//! use futures_lite::future::block_on;
22//! use futures_lite::{stream, StreamExt};
23//!
24//! fn main() {
25//!     block_on(async {
26//!         let a = stream::once(1);
27//!         let b = stream::once(2);
28//!         let c = stream::once(3);
29//!         let mut s = (a, b, c).merge();
30//!
31//!         let mut counter = 0;
32//!         s.for_each(|n| counter += n).await;
33//!         assert_eq!(counter, 6);
34//!     })
35//! }
36//! ```
37//!
38
39#![deny(missing_debug_implementations, nonstandard_style)]
40#![warn(missing_docs, unreachable_pub)]
41
42mod merge;
43mod stream;
44
45pub use merge::MergeStreams;
46pub use stream::{IntoStream, StreamExt};
47
48mod utils;