logoalt Hacker News

tcfhgjyesterday at 7:05 PM1 replyview on HN

sure about that?

the struct in which it is stored, could be generic as well


Replies

Maxataryesterday at 7:56 PM

I'm addressing the intent of the original question.

No one would ask this question in the case where the struct is generic over a type parameter bounded by the trait, since such a design can only store a homogeneous collection of values of a single concrete type implementing the trait; the question doesn't even make sense in that situation.

The question only arises for a struct that must store a heterogeneous collection of values with different concrete types implementing the trait, in which case a trait object (dyn Trait) is required.