Skip to main content

One doc tagged with "orphan-rule"

View all tags

The newtype Pattern to Implement External Traits on External Types

We've seen how to build hierarchies of traits with supertraits, but what happens when we hit a wall with the compiler's rules? One of the most important rules governing traits is the orphan rule, which prevents us from implementing an external trait on an external type. In this article, we'll explore a clever and idiomatic Rust solution to this problem: the newtype pattern.