Orphan rule
Rust's orphan rule restricts trait implementations so that either the trait or the implementing type must be local to the defining crate.
Write Powerful Rust Macros
An orphan rule restricts trait implementations so that at least the trait or the implemented type is local to the defining crate.
- How it is used
- Uses local newtypes to add trait implementations when the desired trait or wrapped type is nonlocal.
- How deep it goes
- Explains the locality requirement, conflicting-implementation rationale, and newtype workaround, but does not detail compiler coherence internals.
- Examples
- Uses a hypothetical Clone implementation for String and a MyString newtype as the concrete workaround.
- What you can do after
- Apply it via a local newtype to implement traits for otherwise nonlocal types.
Idiomatic Rust
Rust's orphan rule restricts trait implementations so that an implementation must involve a locally defined trait or type, subject to its coherence rules.
- How it is used
- Constrains trait implementations in Rust according to local and external ownership of traits and types.
- How deep it goes
- Defines the local/external boundary and a covered-type exception, while directing readers to the language reference for details.
- Examples
- Shows `MyTrait` implemented for `MyStruct1` and `MyStruct2`.
- What you can do after
- Apply the rule by choosing a permitted implementation or using a wrapper struct or extension trait.
Also covered in
What to know first
- traitA trait is a type-level construct that defines reusable behavior or members that types can implement or compose.
Related concepts
- newtype idiomaddressed by · The newtype idiom creates a distinct type by wrapping an existing type, giving its values separate type-level identity while typically preserving their underlying representation.
- type aliascontrasts with · A type alias is a declaration that gives a type or type expression an alternative name without introducing a distinct nominal type.
- traitconfigures · A trait is a type-level construct that defines reusable behavior or members that types can implement or compose.
Questions about orphan rule
What is orphan rule?
Rust's orphan rule restricts trait implementations so that either the trait or the implementing type must be local to the defining crate.
Which Manning books explain orphan rule?
Write Powerful Rust Macros and Idiomatic Rust.
What should I know before learning orphan rule?
Manning books that teach orphan rule usually introduce trait first.
What is the difference between orphan rule and type alias?
Rust's orphan rule restricts trait implementations so that either the trait or the implementing type must be local to the defining crate. A type alias is a declaration that gives a type or type expression an alternative name without introducing a distinct nominal type.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

