Avatar ·

When to use associated types vs generic type parameters in Rust?

Hi! I recently started learning Rust and I'm struggling with one concept. I understand that there are traits with associated types and traits with generic type parameters. Here are examples: ```rust // Associated type trait Container { type Item; fn get(&self) -> Self::Item; } // Generic type trait Container { fn get(&self) -> T; } ``` At first glance they do almost the same thing. But I've read that choosing between them is an important architectural decision. When I write some trait, I don't understand what to choose. For example, I tried to make a trait for converting one type to another — I used a generic parameter. Then for a "collection" trait — I used an associated type. But why? It seems to me that if I use a