1 You need to specify a specific implementation of the trait in order to call the
4 Erroneous code example:
13 impl Generator for Impl {
14 fn create() -> u32 { 1 }
19 impl Generator for AnotherImpl {
20 fn create() -> u32 { 2 }
23 let cont: u32 = Generator::create();
24 // error, impossible to choose one of Generator trait implementation
25 // Should it be Impl or AnotherImpl, maybe something else?
28 This error can be solved by adding type annotations that provide the missing
29 information to the compiler. In this case, the solution is to use a concrete
39 impl Generator for AnotherImpl {
40 fn create() -> u32 { 2 }
43 let gen1 = AnotherImpl::create();
45 // if there are multiple methods with same name (different traits)
46 let gen2 = <AnotherImpl as Generator>::create();