Skip to content

Commit

Permalink
Remove FnBox and use builtin impl FnOnce for Box<FnOnce()> instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
crlf0710 committed Apr 9, 2019
1 parent b93ec30 commit 6585afb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
1 change: 0 additions & 1 deletion ci/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ Filesystem
filesystem's
filesystems
Firefox
FnBox
FnMut
FnOnce
formatter
Expand Down
14 changes: 2 additions & 12 deletions src/ch20-03-graceful-shutdown-and-cleanup.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,7 @@ pub struct ThreadPool {
sender: mpsc::Sender<Message>,
}

trait FnBox {
fn call_box(self: Box<Self>);
}

impl<F: FnOnce()> FnBox for F {
fn call_box(self: Box<F>) {
(*self)()
}
}

type Job = Box<dyn FnBox + Send + 'static>;
type Job = Box<dyn FnOnce + Send + 'static>;

impl ThreadPool {
/// Create a new ThreadPool.
Expand Down Expand Up @@ -536,7 +526,7 @@ impl Worker {
Message::NewJob(job) => {
println!("Worker {} got a job; executing.", id);

job.call_box();
(job)();
},
Message::Terminate => {
println!("Worker {} was told to terminate.", id);
Expand Down

0 comments on commit 6585afb

Please sign in to comment.