Define a type inside a trait with a generic parameter using the `type Name<'a>` syntax to create a Generic Associated Type.
Use Generic Associated Types (GATs) by defining a type inside a trait with a generic parameter, then implementing that type in an impl block.
trait Iterator {
type Item<'a> where Self: 'a;
fn next(&self) -> Option<Self::Item<'_>>;
}
struct MyIter;
impl Iterator for MyIter {
type Item<'a> = &'a str;
fn next(&self) -> Option<Self::Item<'_>> { None }
}
Generic Associated Types let you define a type inside a trait that changes based on a generic parameter, like a lifetime. This is useful when the type you return depends on how long a reference lives, rather than just the data type itself. Think of it like a template for a box where the box's size changes depending on how long you plan to keep it.