我正在从 rust book 设置服务器示例。我将在这里添加相关部分。
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>;
我的实现与书中略有不同。它FnBox在书中而不是FnOnce(). 我打电话给
job.call_box()
这里job是类型Job。但这会引发错误。
| 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`
该特征FnBox已在所有具有FnOnce()特征的类型上实现。所以我不明白为什么它说dyn std::ops::FnOnce() + std::marker::Send : FnBox不满意。
我在这里想念什么?