-
Notifications
You must be signed in to change notification settings - Fork 0
/
async-stream-min.rs
47 lines (41 loc) · 924 Bytes
/
async-stream-min.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![feature(type_alias_impl_trait)]
#![feature(generators)]
#![feature(stmt_expr_attributes)]
#![feature(proc_macro_hygiene)]
use anyhow::{anyhow, Result};
use futures::stream::Stream;
use futures_async_stream::{stream, for_await};
type Op = impl Stream<Item = Result<usize>>;
async fn iter() -> Op {
futures::stream::iter(vec![Ok(1), Err(anyhow!(""))])
}
#[stream(item = Result<usize>)]
async fn transform<S>(stream: S)
where
S: Stream<Item = Result<usize>> + Unpin,
{
#[for_await]
for i in stream {
yield i;
}
}
async fn bad() -> Op {
transform(Box::pin(iter().await))
}
#[allow(dead_code)]
#[stream(item = Result<usize>)]
async fn good() {
#[for_await]
for i in transform(Box::pin(iter().await)) {
yield i;
}
}
#[tokio::main]
async fn main() {
let s = bad().await;
// let s = good();
#[for_await]
for i in s {
println!("{:#?}", i);
}
}