Trait rules
Traits also have special properties and restrictions, which are important to know about when you are using them.
An important property of the type system in the context of traits is the trait coherence rule. The idea of trait coherence is that there should be exactly one implementation of a trait on a type that implements it. This should be quite obvious since, with two implementations there would be ambiguity in what to choose between the two.
Another rule that might confuse many about traits is the orphan rule. The orphan rule, in simple words, states that we cannot implement external traits on external types.
To word it in another way, either the trait must be defined by you if you are implementing something on an external ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access