Macros to create streams from heterogeneous futures
``` async fn test1() -> u8 { 1 } async fn test2() -> u8 { 2 } async fn test3() -> u8 { 3 } async fn test4() -> u8 { 4 }
fn orderedstream() -> impl Stream
fn unorderedstream() -> impl Stream
To allow the creation of a stream from heterogeneous
Future
s with equal
associated Item
s.
The way to create a
Stream
from a set of Future
s is to create a
FuturesOrdered
, or a
FuturesUnordered
.
However, as these store Future
s of
the type they're parameterized over, you can't give them a heterogeneous set of Futures
s.
Here's an example that compiles:
``` async fn test1() -> () { () }
fn to_stream() -> impl Stream Here's an example that doesn't compile: ```
async fn test1() -> () { () } async fn test2() -> () { () } fn to_stream() -> impl Stream Great, very helpful rustc. We've created the exact same function under a different name,
and it's Well, there is a way to combine two different futures pretty easily -- Use
```
async fn test1() -> () { () } async fn test2() -> () { () } fn to_stream() -> impl Stream That's great, now let's try with four ```
async fn test1() -> () { () }
async fn test2() -> () { () }
async fn test3() -> () { () }
async fn test4() -> () { () } fn to_stream() -> impl Stream With four, it's already pretty unwieldy. Luckily, this package exports macros to
generate this all for you.Future
is different somehow.future::Either
Future
s.