async-rs / async-rs/async-std

§3.4 (Sending Messages) in the book requires a different version of futures

Open
#495 3 comments 0 reactions 0 assignees View on GitHub
documentation good first issue
Dominant language
Rust
Stars
4.1k
Forks
339
PR merge metrics
No merged PRs in 30d

Description

## Steps to reproduce

- `futures-preview = { version = "0.3.0-alpha.19", features = [ "async-await" ] }` in `Cargo.toml` as recommended in §3.1.
- Try to build the example in https://book.async.rs/tutorial/sending_messages.html

```rust

use futures::channel::mpsc; // 1
use futures::sink::SinkExt;
use std::sync::Arc;

type Sender = mpsc::UnboundedSender; // 2
type Receiver = mpsc::UnboundedReceiver;

async fn connection_writer_loop(
mut messages: Receiver,
stream: Arc, // 3
) -> Result<()> {
let mut stream = &*stream;
while let Some(msg) = messages.next().await {
stream.write_all(msg.as_bytes()).await?;
}
Ok(())
}
```

## What happens

```
error[E0599]: no method named `next` found for type `futures_channel::mpsc::UnboundedReceiver` in the current scope
--> core/src/main.rs:89:36
|
89 | while let Some(msg) = messages.next().await {
| ^^^^ method not found in `futures_channel::mpsc::UnboundedReceiver`
|
= note: the method `next` exists but the following trait bounds were not satisfied:
`futures_channel::mpsc::UnboundedReceiver : async_std::stream::stream::StreamExt`
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
7 | use futures_util::stream::StreamExt;
|
```

It seems to work with `futures = "0.3.0"`, and it's indeed what is being used in the `a-chat` example in the repo as of 122e87364bef463c5afbf7681ec3ce35a3a7f577.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.