tokio-rs / website

Website for the Tokio project
https://tokio.rs
MIT License
229 stars 329 forks source link

Update select.md, fix example error #651

Closed createyourpersonalaccount closed 2 years ago

createyourpersonalaccount commented 2 years ago

error[E0277]: () doesn't implement std::fmt::Display.

We use the display of the Debug trait instead.

createyourpersonalaccount commented 2 years ago

I noticed later that the hidden lines with # fix this error by giving a string type to the channel. Should the examples rely on hidden # to work? It's less obvious that there's required hidden lines when the program seems complete. I knew some of the examples were incomplete because they did not have a visible main(), for example.

Darksonn commented 2 years ago

Maybe a better example would include a call to tokio::spawn that creates a task that sends a string on each channel.

createyourpersonalaccount commented 2 years ago

@Darksonn Perhaps the lines

# tx1.clone().send("hello").await.unwrap();
# drop((tx1, tx2, tx3));

should be unhidden? They're already there, just hidden in the source of the select.md file, not visible from the website tutorial.

Darksonn commented 2 years ago

Those lines don't really make a great example, is why I suggested a tokio::spawn call. I think that would be a more realistic example.

createyourpersonalaccount commented 2 years ago

@Darksonn In my opinion the {:?} fix is a simple and effective one.

You have to consider the mindset of the reader who has reached that point in the tutorial, they already understand what spawn() does and how channels work.

I will leave this open for you to choose what to do but I will not continue beyond checking your response if you give one because we're entering bikeshedding territory.