Marker trait
A marker trait is a trait without methods or associated properties that classifies implementing types or conveys compile-time information.
Write Powerful Rust Macros
A marker trait is a trait with no methods or associated properties that classifies implementing types.
- How it is used
- Enforces valid traffic-light transitions and required builder-field sequences at compile time.
- How deep it goes
- Works through marker traits, empty state structs, generic bounds, PhantomData, specialized implementations, generated builder states, and compile-fail testing.
- Examples
- Uses Green and Red traffic lights, a Gleipnir builder, generated field-state structs, a successful builder test, and a missing-property compile test.
- What you can do after
- Build it from scratch to encode state transitions and restrict build methods to completed builder states.
Idiomatic Rust
A marker trait is a Rust trait that conveys compile-time information about a type without necessarily defining methods or other behavior.
- How it is used
- Names type attributes or a combination of trait bounds so generic code can require them through one marker.
- How deep it goes
- Works through an empty trait, blanket implementation, derived type, and generic bound; offers no single prescribed use case.
- Examples
- Uses a derived unit struct, an empty `FullFeatured` trait, its blanket implementation, and a generic container constrained by that trait.
- What you can do after
- Build it from scratch with an empty trait and blanket implementation, then use it as a generic bound.
Related concepts
- Syncincludes · Sync is a Rust marker trait indicating that references to a value can be shared safely between threads.
- Sendincludes · Send is a Rust marker trait indicating that a value can be transferred safely between threads.
- traitkind of · 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.

