Skip to content

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

Open
@Ppjet6

Description

@Ppjet6

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 122e873.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions