Ah, sorry, I think I assumed too much.
When we create
DogT is unsized. Fro here on out I’ll use the new nomenclature
dyn DogT to refer to this unsized dynamic trait. There can’t exist a value of
dyn DogT on the stack because it could be any number of different strict, all with different sizes, and the stack needs fixed sized values.
Your original code works without
DogT: Clone specifically because you have a value
Box<dyn DogT>, not
dyn DogT. The box has a fixed size, and the dynamic size is hidden in an allocation.
dyn DogT: Clone would similarly fail because you would need a single concrete function
<dyn DogT>::clone which returns a
dyn DogT. But
dyn DogT cannot exist without a box or other indirection because it does not have a fi ed size. Thus this function cannot exist.
I focused on
Box<dyn DogT>::clone because while it doesn’t exist, a function like it could. Since it would return a
Box<dyn DogT>, not a raw
dyn DogT, the return value could actually exist on the stack and the definition could work.
If you haven’t read it already, this book chapter section will probably be helpful? https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait. It doesn’t talk about sized in relation to traits but it might give some background knowledge in a more structured way than I can present it.