Async-std: 搂3.4 (Sending Messages) in the book requires a different version of futures

Created on 10 Nov 2019  路  2Comments  路  Source: async-rs/async-std

Steps to reproduce

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

type Sender<T> = mpsc::UnboundedSender<T>; // 2
type Receiver<T> = mpsc::UnboundedReceiver<T>;

async fn connection_writer_loop(
    mut messages: Receiver<String>,
    stream: Arc<TcpStream>, // 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<std::string::String>` 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<std::string::String>`
   |
   = note: the method `next` exists but the following trait bounds were not satisfied:
           `futures_channel::mpsc::UnboundedReceiver<std::string::String> : 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.

documentation good first issue

Most helpful comment

I like to take it if nobody is working on it now

All 2 comments

@Ppjet6 Thanks for filing this! We should indeed fix this. I've marked this as "good first issue" as it should be relatively easy to update.

I like to take it if nobody is working on it now

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kornelski picture kornelski  路  5Comments

zys864 picture zys864  路  4Comments

zkat picture zkat  路  6Comments

yoshuawuyts picture yoshuawuyts  路  3Comments

Darksonn picture Darksonn  路  7Comments