Skip to content

Commit 80c03da

Browse files
authored
Document for await syntax (#45)
* Document for await syntax * Make `README.md` a symlink to `async-stream/README.md`
1 parent ba314cf commit 80c03da

File tree

3 files changed

+8
-180
lines changed

3 files changed

+8
-180
lines changed

README.md

Lines changed: 0 additions & 163 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
async-stream/README.md

async-stream/README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ async fn main() {
6868
}
6969
```
7070

71-
Streams may be implemented in terms of other streams:
71+
Streams may be implemented in terms of other streams - `async-stream` provides `for await`
72+
syntax to assist with this:
7273

7374
```rust
7475
use async_stream::stream;
@@ -89,8 +90,7 @@ fn double<S: Stream<Item = u32>>(input: S)
8990
-> impl Stream<Item = u32>
9091
{
9192
stream! {
92-
pin_mut!(input);
93-
while let Some(value) = input.next().await {
93+
for await value in input {
9494
yield value * 2;
9595
}
9696
}
@@ -124,7 +124,7 @@ fn bind_and_accept(addr: SocketAddr)
124124
-> impl Stream<Item = io::Result<TcpStream>>
125125
{
126126
try_stream! {
127-
let mut listener = TcpListener::bind(&addr)?;
127+
let mut listener = TcpListener::bind(addr).await?;
128128

129129
loop {
130130
let (stream, addr) = listener.accept().await?;
@@ -148,17 +148,7 @@ stored on the stack. A pointer to the cell is stored in a thread local and
148148
`sender.send(value)` stores the value that cell and yields back to the
149149
caller.
150150

151-
## Limitations
152-
153-
`async-stream` suffers from the same limitations as the [`proc-macro-hack`]
154-
crate. Primarily, nesting support must be implemented using a `TT-muncher`.
155-
If large `stream!` blocks are used, the caller will be required to add
156-
`#![recursion_limit = "..."]` to their crate.
157-
158-
A `stream!` macro may only contain up to 64 macro invocations.
159-
160151
[`Stream`]: https://docs.rs/futures-core/*/futures_core/stream/trait.Stream.html
161-
[`proc-macro-hack`]: https://github.com/dtolnay/proc-macro-hack/
162152

163153
## License
164154

async-stream/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
//! }
7676
//! ```
7777
//!
78-
//! Streams may be implemented in terms of other streams:
78+
//! Streams may be implemented in terms of other streams - `async-stream` provides `for await`
79+
//! syntax to assist with this:
7980
//!
8081
//! ```rust
8182
//! use async_stream::stream;
@@ -96,8 +97,7 @@
9697
//! -> impl Stream<Item = u32>
9798
//! {
9899
//! stream! {
99-
//! pin_mut!(input);
100-
//! while let Some(value) = input.next().await {
100+
//! for await value in input {
101101
//! yield value * 2;
102102
//! }
103103
//! }

0 commit comments

Comments
 (0)