cognitive-engineering-lab / rust-book

The Rust Programming Language: Experimental Edition
https://rust-book.cs.brown.edu
Other
504 stars 82 forks source link

The walkthrough in Section 20.2 is missing a step #138

Open langhisc opened 7 months ago

langhisc commented 7 months ago

URL to the section(s) of the book with this problem:

https://rust-book.cs.brown.edu/ch20-02-multithreaded.html

Description of the problem:

Listing 20-17 should show an additional change. In the definition of the Worker struct, the thread field’s type changes from thread::JoinHandle<()> to thread::JoinHandle<mpsc::Receiver<Job>>, but the tutorial forgets to mention this, and Listing 20-17 doesn't feature that change (although it should). If the reader follows the book’s walkthrough step-by-step, then after implementing Listing 20-17, they encounter a different error than the book says they will encounter. The error predicted by the book is the one that would occur if Listing 20-17 did contain the additional change.

Suggested fix:

Modify Listing 20-17 so that, in the definition of the Worker struct, the thread field’s type changes from thread::JoinHandle<()> to thread::JoinHandle<mpsc::Receiver<Job>>.

langhisc commented 7 months ago

A similar issue exists in Listing 20-18. The tutorial says the code there will compile, but it doesn't, because the type of thread in Worker has not been updated to match the rest of the new code.