4 ms·
Sorry, you are right about that. You can have trait objects without an allocator. I'm not sure how common a pattern that is. Many people like to avoid trait ob
by lambda 9y ago
Sorry, you are right about that. You can have trait objects without an allocator.
I'm not sure how common a pattern that is. Many people like to avoid trait objects and just parameterize the function on a type bounded by the trait in that case. And impl Trait is replacing some of the other cases in which you had to return an allocated trait object.
Anyhow, you're right, I was wrong that people couldn't be using trait objects in an embedded context with no allocator, but I also think it's perfectly reasonable to write in a subset of Rust in which you don't use trait objects at all.
- Argorak 9y agoTaking a trait object by reference is a pretty common pattern. Box<Trait> is so pervasive because it's currently the easiest way to get type erasure in return position.