I see what you mean. T: DynSized as currently written still works with Box<T>, and can be copied around with no problems, but it doesn’t work with Rc<T>.
In particular, that means that Rc<Thin<dyn Trait>> doesn’t work. I think it’s really important that we get that working, so let’s think about it for a second. Here’s what the monomorphized type RcBox<Thin<dyn Trait>> looks like:
struct RcBox<Thin<dyn Trait> {
strong: ...,
weak: ...,
value: Thin<dyn Trait> {
meta: <dyn Trait>::Meta, // stored at alignment of <Thin<dyn Trait>>
data: dyn Trait
}
}
The problem is, the value field of RcBox, is stored at an offset determined by Thin<dyn Trait>'s alignment, which is only determined by reading value.meta. but value.meta is stored at that alignment, meaning we have a chicken-or-egg problem and have to read value.meta to read value.meta.
The solution, I guess, is to “lift” the meta field out into the containing RcBox
struct, and store it at the proper alignment of a <dyn Trait>::Meta. That would look like this:
struct RcBox<Thin<dyn Trait>> {
strong: ...,
weak: ...,
value.meta: <dyn Trait>::Meta, // stored at alignment of <dyn Trait::Meta>
value: Thin<dyn Trait> {
data: dyn Trait
}
}
What we need for Thin to work is a way to tell the compiler that a Thin<T>, when stored as a field in a containing struct, should have the meta field separated out and stored at its own static alignment. A Thin<T> by itself would always be stored at the alignment of the T stored within (assuming it’s larger than the alignment of the T::Meta also stored within), and an RcBox<Thin<T>> would also be stored at the alignment of the T stored within, however the padding between the meta and data field of the Thin<T> could vary depending on whether the Thin<T> is stored by itself or as a field in a struct.
I’m not sure what traits we would need for that. Something to experiment with though.
Unless someone comes up with a better solution. There’s also the option of just creating ThinRc<T>, ThinBox<T> and other Thin*<T> pointer types, but then you have to create a “thin” version of each pointer type.