Skip to content

Book: unresolved import futures::select #89

Closed
@SuperFluffy

Description

@SuperFluffy

In the current version of the book, the final code of the Handling Disconnection tutorial doesn't work:

use futures::{
    channel::mpsc,
    SinkExt,
    FutureExt,
    select,
};

---

error[E0432]: unresolved import `futures::select`
  --> src/main.rs:13:5
   |
13 |     select,
   |     ^^^^^^ no `select` in the root

futures-preview 0.3.0-alpha.17 actually defines two select! macros, futures::future::select and futures::stream::select, see its lib.rs.

Changing the import to stream::select (I hope I understood it correctly, given that we are working with streams; either way, importing future::select has the same issue) makes the import work, but it cannot resolve the macro still:

async fn client_writer(
    messages: &mut Receiver<String>,
    stream: Arc<TcpStream>,
    mut shutdown: Receiver<Void>,
) -> Result<()> {
    let mut stream = &*stream;
    loop {
        select! {
            msg = messages.next().fuse() => match msg {
                Some(msg) => stream.write_all(msg.as_bytes()).await?,
                None => break,
            },
            void = shutdown.next().fuse() => match void {
                Some(void) => match void {},
                None => break,
            }
        }
    }
    Ok(())
}

---

error: cannot find macro `select!` in this scope
  --> src/main.rs:92:9
   |
92 |         select! {
   |         ^^^^^^

error: cannot find macro `select!` in this scope
   --> src/main.rs:126:21
    |
126 |         let event = select! {
    |                     ^^^^^^

warning: unused import: `future::select`
  --> src/main.rs:13:5
   |
13 |     future::select,
   |     ^^^^^^^^^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions