For reference, I’ve got a custom RFC draft at https://github.com/kennytm/rfcs/tree/dyn-type/text/0000-dyn-type, but far from complete even for Pre-RFC. I believe there should a dedicated syntax for declaring custom DST instead of simply impl Referent for T.
Some opinions on this Pre-RFC from what I’ve learned there:
-
DynAligneddoesn’t work. The minimal promise a type can give about alignment, if any, isAlignFromMeta. This is because in a DST structstruct X<T: DynAligned> { a: u8, b: T, }if you need to read
&x.b, you’ll first need to find the offset ofb, which in turn requires knowing the alignment ofbwithout knowing its pointer value.Even if
DynAlignedis more flexible, I don’t think any types need such flexibility, or can do anything useful with it. So I’d recommend reducing the hierarchy to 5 traits (removeDynAlignedand collapseAlignFromMetaintoDynSized):Referent (extern type) DynSized: Referent (just a super trait for SizeFromMeta and Aligned) SizeFromMeta: DynSized (dyn Trait) Aligned: DynSized (CStr, Thin) Sized: Aligned + SizeFromMeta (u8, u16) -
Deprecating
?Sizedin favor of a white-list of special traits is interesting. As you mentioned, I have some worry about the interaction withMovethough. Would this meanT: SizedbecomesT: Sized + ?Move? Wouldn’t it break backward compatibility?An alternative idea is to make
?means?Sized—T: DynSized + ?. The+ ?looks very cryptic, but is still better than theSized + ?Sizednonsense (this means?Move).