Its easy to describe actual problem with code, lets say I am using a library called animals
use animals::Duck;
let mut duck = Duck::new();
duck.walk();
duck.swim();
duck.fly();
// custom method
duck.talk();
Of course, duck can't talk, But how to implement our own method for Duck ?
impl Duck {
fn talk(&self) { ... }
}
I got this error:
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
|
| / impl Duck {
| | fn talk(&self) { ... }
| | }
| |_^ impl for type defined outside of crate.
|
= note: define and implement a trait or new type instead
note that the method call syntax with such a trait is only available if the trait is in scope, so from a different module you’d need to include a use your::path::to::DuckExt; item.