Quantcast
Channel: When is it appropriate to use an associated type versus a generic type? - Stack Overflow
Browsing latest articles
Browse All 4 View Live

Answer by solstice333 for When is it appropriate to use an associated type...

Associated types can be used to tell the compiler "these two types between these two implementations are the same". Here's a double dispatch example that compiles, and is almost similar to how the...

View Article


Answer by Matthieu M. for When is it appropriate to use an associated type...

This is now touched on in the second edition of The Rust Programming Language. However, let's dive in a bit in addition.Let us start with a simpler example.When is it appropriate to use a trait...

View Article


Answer by Steve Klabnik for When is it appropriate to use an associated type...

Associated types are a grouping mechanism, so they should be used when it makes sense to group types together.The Graph trait introduced in the documentation is an example of this. You want a Graph to...

View Article

When is it appropriate to use an associated type versus a generic type?

In this question, an issue arose that could be solved by changing an attempt at using a generic type parameter into an associated type. That prompted the question "Why is an associated type more...

View Article
Browsing latest articles
Browse All 4 View Live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>