Just a basic programmer living in California
To expand on why generics are preferred, just in case you haven’t seen these points yet: the performance downsides of Box<dyn MyTrait>
are,
There is also a possible type theory objection which is that normally there is a distinction between types and traits. Traits are not types themselves, but instead define sets of types with shared behavior. (That’s why the same feature in Haskell is called a “type class”, because it defines a class of types that have something in common.) But dyn
turns a trait into a type which undermines the type/trait distinction. It’s useful enough to justify being in the language, but a little unsettling from a certain perspective.
Yeah the performance differences don’t matter in most cases. Rust makes it tempting to optimize everything because the language is explicit about runtime representations. But that doesn’t mean that optimizing is the best use of your time.