tokio-rs / doc-push

Tokio doc blitz effort - A concerted effort to improve Tokio's documentation.
MIT License
50 stars 7 forks source link

Feedback - Getting Started - Hello World! #65

Closed rawrmonstar closed 4 years ago

rawrmonstar commented 6 years ago

Hi I'm trying to learn Tokio right now and I've started to go through the documentation. Something that I found confusing in the Getting Started - Hello World - Creating the stream section. The first code block in the section is:

fn main() {
    // Parse the address of whatever server we're talking to
    let addr = "127.0.0.1:6142".parse().unwrap();
    let stream = TcpStream::connect(&addr);

    // Following snippets come here...
}

and it's shortly followed up with another code block:

let hello_world = TcpStream::connect(&addr).and_then(|stream| {
    println!("created stream");

    // Process stream here.

    Ok(())
})
.map_err(|err| {
    // All tasks must have an `Error` type of `()`. This forces error
    // handling and helps avoid silencing failures.
    //
    // In our example, we are only going to log the error to STDOUT.
    println!("connection error = {:?}", err);
});

To me, it seems like the stream variable in the first block is not actually used anywhere, is that correct? If so, I think the // Following snippets come here... comment is a bit misleading 🤔

rylev commented 6 years ago

This is good feedback. stream and hello_world are the same variables. We should make that abundantly clear.

ultrasaurus commented 4 years ago

I think this is clearer with Rust async / await syntax. This example got rewritten to remove this problem in the migration to 0.2, so closing this issue