- I have searched open and closed issues and pull requests for duplicates, using these search terms:
- I have checked the latest
main branch to see if this has already been fixed, in this file:
listings/ch21-web-server/no-listing-07-final-code/src/lib.rs
URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch21-03-graceful-shutdown-and-cleanup.html
Description of the problem:
Section 21.3 "Implementing the Drop Trait on ThreadPool" mentions:
However, the only time this would come up would be when dropping the Worker[...]
In this case, a better alternative exists: the Vec::drain method[...]
and then provides this snippet:
for worker in self.workers.drain(..) {
println!("Shutting down worker {}", worker.id);
worker.thread.join().unwrap();
}
Listing 21-23 reflects this usage of drain instead of making thread an Option, but the final code does not.
Suggested fix:
Correct final code to use the Vec::drain strategy and not make thread and Option (as initiated in #3248).
I will open a PR to address this within the day.
21.321 final codemainbranch to see if this has already been fixed, in this file:listings/ch21-web-server/no-listing-07-final-code/src/lib.rsURL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch21-03-graceful-shutdown-and-cleanup.html
Description of the problem:
Section 21.3 "Implementing the Drop Trait on ThreadPool" mentions:
and then provides this snippet:
Listing 21-23 reflects this usage of
draininstead of makingthreadanOption, but the final code does not.Suggested fix:
Correct final code to use the
Vec::drainstrategy and not makethreadandOption(as initiated in #3248).I will open a PR to address this within the day.