I have a Vec
where T
implements Foo
. Why can I not coerce it to a Vec
even thou
Because Box<Bar>
is a different size than Box<Foo>
. The coercion is allowed on a single value, but here you'd have to resize the whole vector. The book goes into some detail on this in the section on Representation of Trait Objects. Short version: Box<Bar>
is a pointer to a value. Box<Foo>
is a pointer to a value and a pointer to a vtable.