`PhantomData` is a zero-sized marker struct for a relationship that matters to Rust’s type system but does not require a stored value. A generic struct can use it to carry a type parameter: `Dog<Breed>` can distinguish breeds at compile time while storing only the dog’s name. Without a field using `Breed`, the compiler reports that the parameter is unused. section 2.1.5
Make a generic parameter count
```rust use std::marker::PhantomData; struct Poodle {} struct Dog<Breed> { name: String, breed: PhantomData<Breed>, } let dog: Dog<Poodle> = Dog { name: "Jeffrey".into(), breed: PhantomData, }; ``` The field must be initialized, but it stores no `Poodle` value. The annotation `Dog<Poodle>` supplies the concrete type for the marker. section 2.1.5
The type tag can select behavior without adding breed state. For example, `impl Dog<Poodle> { fn breed_name(&self) -> &str { "poodle" } }` defines a method for that concrete type. Other breeds can have their own `impl` blocks; a missing specialization is caught when code tries to call its absent method. Use `impl Dog<Poodle>`, not `impl<Breed> Dog<Breed>`, when the behavior is breed-specific. section 2.1.5
A phantom field can also record a lifetime. An iterator with `phantom: PhantomData<&'a T>` carries `'a` in its type even though the field holds no reference. In the linked-list iterator example, this accompanies pointer-backed state used to return references. That implementation also requires `unsafe`; adding `PhantomData` is not a substitute for making those references valid. section 3.2.4
