How to use PhantomData

Use PhantomData<T> as a struct field to inform the compiler about ownership or borrowing relationships for types that are not directly stored.

Use PhantomData<T> as a struct field to tell the compiler your type logically owns or borrows T without storing it, ensuring correct variance and drop behavior. Add use std::marker::PhantomData; and define a private field like _marker: PhantomData<T> in your struct.

use std::marker::PhantomData;

struct MyStruct<T> {
    _marker: PhantomData<T>,
}

This pattern is essential for types like TypedArena<T> where the compiler needs to know that dropping the arena must drop the T instances it manages, even if T isn't a direct field.