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.
Related concepts
- newtype idiomaddressed by · The newtype idiom defines a distinct type by wrapping an existing type, typically preserving its representation while enabling type-specific distinctions or behavior.
- type aliascontrasts with · A type alias is a declaration that gives an existing type an alternative name without creating a distinct type or representation.
- traitcontrasts with · A trait is a type-level construct that defines reusable behavior or members that types can implement or compose.
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.

