I am working on the setting up a server example from the rust book. I will add the relevant parts here.
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 FnOnce() + Send + 'static>;
my implementation which is slightly changed from the book. It is FnBox
in book rather than FnOnce()
. And I call
job.call_box()
Here job
is of the type Job
. But this throws an error.
| job.call_box();
| ^^^^^^^^
|
= note: job is a function, perhaps you wish to call it
= note: the method `call_box` exists but the following trait bounds were not satisfied:
`dyn std::ops::FnOnce() + std::marker::Send : FnBox`
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `call_box`, perhaps you need to implement it:
candidate #1: `FnBox`
The trait FnBox
has been implemented on all the types with FnOnce()
trait. So I do not understand why it says dyn std::ops::FnOnce() + std::marker::Send : FnBox
is not satisfied.
What am I missing here?