相关疑难解决方法(0)

特征"A"没有为"A"类型实现

我试图使用一个具有函数的特征,该函数将闭包作为参数,然后在特征对象上使用它.

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)

版本rustcrustc 1.0.0-beta.3 (5241bf9c3 2015-04-25) (built 2015-04-25).

traits rust

5
推荐指数
1
解决办法
1447
查看次数

标签 统计

rust ×1

traits ×1