diff --git a/listings/ch21-web-server/no-listing-07-final-code/src/lib.rs b/listings/ch21-web-server/no-listing-07-final-code/src/lib.rs index e8decb0cc2..8db88f20ed 100644 --- a/listings/ch21-web-server/no-listing-07-final-code/src/lib.rs +++ b/listings/ch21-web-server/no-listing-07-final-code/src/lib.rs @@ -51,19 +51,17 @@ impl Drop for ThreadPool { fn drop(&mut self) { drop(self.sender.take()); - for worker in &mut self.workers { + for worker in self.workers.drain(..) { println!("Shutting down worker {}", worker.id); - if let Some(thread) = worker.thread.take() { - thread.join().unwrap(); - } + worker.thread.join().unwrap(); } } } struct Worker { id: usize, - thread: Option>, + thread: thread::JoinHandle<()>, } impl Worker { @@ -86,9 +84,6 @@ impl Worker { } }); - Worker { - id, - thread: Some(thread), - } + Worker { id, thread } } }