1//! The `stream_select` macro.
2
3#[allow(unreachable_pub)]
4#[doc(hidden)]
5pub use futures_macro::stream_select_internal;
6
7/// Combines several streams, all producing the same `Item` type, into one stream.
8/// This is similar to `select_all` but does not require the streams to all be the same type.
9/// It also keeps the streams inline, and does not require `Box<dyn Stream>`s to be allocated.
10/// Streams passed to this macro must be `Unpin`.
11///
12/// If multiple streams are ready, one will be pseudo randomly selected at runtime.
13///
14/// # Examples
15///
16/// ```
17/// # futures::executor::block_on(async {
18/// use futures::{stream, StreamExt, stream_select};
19/// let endless_ints = |i| stream::iter(vec![i].into_iter().cycle()).fuse();
20///
21/// let mut endless_numbers = stream_select!(endless_ints(1i32), endless_ints(2), endless_ints(3));
22/// match endless_numbers.next().await {
23/// Some(1) => println!("Got a 1"),
24/// Some(2) => println!("Got a 2"),
25/// Some(3) => println!("Got a 3"),
26/// _ => unreachable!(),
27/// }
28/// # });
29/// ```
30#[macro_export]
31macro_rules! stream_select {
32 ($($tokens:tt)*) => {{
33 use $crate::__private as __futures_crate;
34 $crate::stream_select_internal! {
35 $( $tokens )*
36 }
37 }}
38}
39