1 There are conflicting trait implementations for the same type.
3 Erroneous code example:
7 fn get(&self) -> usize;
10 impl<T> MyTrait for T {
11 fn get(&self) -> usize { 0 }
18 impl MyTrait for Foo { // error: conflicting implementations of trait
19 // `MyTrait` for type `Foo`
20 fn get(&self) -> usize { self.value }
24 When looking for the implementation for the trait, the compiler finds
25 both the `impl<T> MyTrait for T` where T is all types and the `impl
26 MyTrait for Foo`. Since a trait cannot be implemented multiple times,
27 this is an error. So, when you write:
31 fn get(&self) -> usize;
34 impl<T> MyTrait for T {
35 fn get(&self) -> usize { 0 }
39 This makes the trait implemented on all types in the scope. So if you
40 try to implement it on another one after that, the implementations will
45 fn get(&self) -> usize;
48 impl<T> MyTrait for T {
49 fn get(&self) -> usize { 0 }
57 f.get(); // the trait is implemented so we can use it