What's the difference of keyword type's effect in aliases and associated types contexts?

// `A` and `B` are defined in the trait via the `type` keyword.
// (Note: `type` in this context is different from `type` when used for
// aliases). 
trait Contains {
    type A;
    type B;

    // Updated syntax to refer to these new types generically.
    fn contains(&self, &Self::A, &Self::B) -> bool;
}

Following the rustbyexample, it reads that Note: type in this context is different from type when used for aliases .
so I wonder what's the difference? could you explain for me? thank you. :slight_smile:

In

type A = u32;

outside of a trait, you are simply creating an alias, whereas in the example above, you're declaring an associated type, which is extremely useful for generic programming with traits. For more information on its utility, see the relevant chapter in the Rust book.

2 Likes

Thank you