为什么这个不起作用:
我认为如果类型重叠,它稍后会被检查。
trait Update {
fn update(&mut self);
}
trait A {}
trait B {}
impl<T: A> Update for T {
fn update(&mut self) {
println!("A")
}
}
impl<U: B> Update for U {
fn update(&mut self) {
println!("B")
}
}
error[E0119]: conflicting implementations of trait `Update`:
--> src/main.rs:14:1
|
8 | impl<T: A> Update for T {
| ----------------------- first implementation here
...
14 | impl<U: B> Update for U {
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
我认为如果类型重叠,它稍后会被检查。
A
和B
的结构体。当您在其上调用update()
时,您会期望什么输出?使用特化,将使用“最具体”的实现,但在这里,A
和B
是完全等效的。 - Peter Hall