我试图使用一个具有函数的特征,该函数将闭包作为参数,然后在特征对象上使用它.
trait A {
fn f<P>(&self, p: P) where P: Fn() -> ();
}
struct B {
a: Box<A>
}
impl B {
fn c(&self) {
self.a.f(|| {});
}
}
Run Code Online (Sandbox Code Playgroud)
此代码段会生成以下错误:
the trait `A` is not implemented for the type `A` [E0277]
Run Code Online (Sandbox Code Playgroud)
版本rustc是rustc 1.0.0-beta.3 (5241bf9c3 2015-04-25) (built 2015-04-25).