Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why not remove trait FnBox ? #106

Open
zydxhs opened this issue May 3, 2020 · 1 comment
Open

Why not remove trait FnBox ? #106

zydxhs opened this issue May 3, 2020 · 1 comment

Comments

@zydxhs
Copy link

zydxhs commented May 3, 2020

FnOnce already replaces FnBox, so why implement it yourself?

  1. 删除以下代码:
trait FnBox {
    fn call_box(self: Box<Self>);
}

impl<F: FnOnce()> FnBox for F {
    fn call_box(self: Box<F>) {
        (*self)()
    }
}
  1. 修改代码
type Thunk<'a> = Box<FnBox + Send + 'a>;

改成

type Thunk<'a> = Box<dyn FnOnce() -> () + Send + 'a>;
job.call_box();

改成

job();
@dns2utf8
Copy link
Member

Hi @zydxhs

This was implemented to be compatible with rust 1.9.x back in the day.
With the threadpool 2.0 this might change, however dereferencing the supplied closure required because it enables a VTable.

Does this answer you question?

Cheers
Stefan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants