Skip to content

TcpListener echo example is confusing #468

Open
@95th

Description

@95th

Echo server example in TcpListener seems confusing to a new-comer.

while let Some(stream) = incoming.next().await {
    let stream = stream?;          -- Immutable binding
    let (reader, writer) = &mut (&stream, &stream);  -- This take mutable reference of immutable references
    io::copy(reader, writer).await?; -- but io requires mutable access.
}

It's not clear how io::copy can use reader and writer which are basically &mut &TcpStream

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions