上QQ阅读APP看书,第一时间看更新
Rules
There are some rules that must be followed in order to use traits. The compiler will throw an error if they are not respected:
- The trait must be imported in order to use its methods
- The implementation of a trait must be in the same crate as the trait or the type
The second rule is to avoid conflicts that could otherwise happen when using multiple libraries. We can have such a conflict when two imported traits provide the same method for the same type.