You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
15: Add async_try_stream to support ? operator in async stream r=taiki-e a=taiki-e
`?` operator can be used with the `#[async_try_stream]` attribute and `async_try_stream_block!` macro.
```rust
#![feature(generators)]
use futures::stream::Stream;
use futures_async_stream::try_async_stream;
#[async_try_stream(ok = i32, error = Box<dyn std::error::Error + Send + Sync + 'static>)]
async fn foo(stream: impl Stream<Item = String>) {
#[for_await]
for x in stream {
yield x.parse()?;
}
}
```
Closes#2
Co-authored-by: Taiki Endo <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+20-4Lines changed: 20 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Add this to your `Cargo.toml`:
27
27
```toml
28
28
[dependencies]
29
29
futures-async-stream = "0.1.0-alpha.5"
30
-
futures-preview = "0.3.0-alpha.17"
30
+
futures-preview = "0.3.0-alpha.18"
31
31
```
32
32
33
33
The current futures-async-stream requires Rust nightly 2019-08-21 or later.
@@ -150,10 +150,27 @@ impl Foo for Bar {
150
150
}
151
151
```
152
152
153
+
## `#[async_try_stream]` and `async_try_stream_block!`
154
+
155
+
`?` operator can be used with the `#[async_try_stream]` and `async_try_stream_block!`. The `Item` of the returned stream is `Result` with `Ok` being the value yielded and `Err` the error type returned by `?` operator or `return Err(...)`.
0 commit comments