This is a no_std
compatible library to author a Future
with Stream
implemented.
You can author simply with await
and yield
.
A nightly feature generators
is required.
``` rust
use stream_future::stream;
enum Prog { Stage1, Stage2, }
async fn foo() -> Result
use tokio_stream::StreamExt;
let bar = foo(); tokio::pin!(bar); while let Some(prog) = bar.next().await { println!("{:?}", prog); } let bar = bar.await?; assert_eq!(bar, 0); ```
``` rust
use streamfuture::trystream;
enum Prog { Stage1, Stage2, }
async fn foo() -> Result<()> { yield Prog::Stage1; // some works... yield Prog::Stage2; // some other works... Ok(()) }
let bar = foo(); tokio::pin!(bar); while let Some(prog) = bar.try_next().await? { println!("{:?}", prog); } ```
You can specify the yield type in the attribute. Either the yield type or return type could be ()
.
You can simply await
other futures, and the macro will handle that.
async-stream
You can return any value you like! The caller can simply await
and get the value without iterate the stream.
This library is 7x faster than async-stream
, according to our benchmark.