Marker trait
A marker trait is a trait that classifies implementing types or conveys information about them without defining methods.
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.
What to know first
- DebugDebug is a Rust standard-library formatting trait for producing programmer-oriented representations of values.
Related concepts
- Sendincludes · Send is a Rust marker trait indicating that a value can be transferred safely between threads.
- Syncincludes · Sync is a Rust marker trait indicating that references to a value can be shared safely between threads.
- traitkind of · A trait is a type-level construct that defines reusable behavior or members that types can implement or compose.
Questions about marker trait
What is marker trait?
A marker trait is a trait that classifies implementing types or conveys information about them without defining methods.
Which Manning books explain marker trait?
Write Powerful Rust Macros and Idiomatic Rust.
What should I know before learning marker trait?
Manning books that teach marker trait usually introduce Debug first.
What is the difference between marker trait and struct tagging?
A marker trait is a trait that classifies implementing types or conveys information about them without defining methods. Struct tagging is a Rust pattern that uses an otherwise empty struct type as a generic type parameter to attach compile-time state or labels to values.
What kinds of marker trait are there?
Kinds of marker trait include Send and Sync.
What is marker trait a kind of?
Marker trait is a kind of trait. A Rust trait defines shared behavior that types can implement.
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.

