use std::borrow::Borrow;
trait Foo {
fn bar();
}
struct S {}
impl <B: Borrow<S>> Foo for B {
fn bar(){
print!("bar");
}
}
struct D {}
impl <B: Borrow<D>> Foo for B {
fn bar(){
print!("bar")
}
}
fn main() {}
上面的代码会导致编译器错误:
Compiling playground v0.0.1 (/playground)
error[E0119]: conflicting implementations of trait `Foo`:
--> src/main.rs:17:5
|
9 | impl <B: Borrow<S>> Foo for B {
| ----------------------------- first implementation here
...
17 | impl <B: Borrow<D>> Foo for B {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
只有一个实现此特征的结构时,可接受的答案会很好。
如果我想同时为Foo
和Borrow<S>
实现特征Borrow<D>
,怎么办?