Crate stream_future
source · [−]Expand description
A Future with item yielded.
#![feature(generators)]
#[derive(Debug)]
enum Prog {
Stage1,
Stage2,
End,
}
#[stream(Prog)]
async fn foo() -> Result<i32> {
yield Prog::Stage1;
// some works...
yield Prog::Stage2;
// some other works...
yield Prog::End;
Ok(0)
}
let bar = foo();
tokio::pin!(bar);
while let Some(prog) = bar.next().await {
println!("{:?}", prog);
}
let bar = bar.await?;
assert_eq!(bar, 0);If a lifetime is needed, specify it in the attribute:
#![feature(generators)]
enum Prog {
Stage1,
Stage2,
}
#[stream(Prog, lifetime = "'a")]
async fn foo<'a>(s: &'a str) {
yield Prog::Stage1;
println!("{}", s);
yield Prog::Stage2;
}
foo("Hello world!").await;Traits
A stream of values produced asynchronously.