I'm thinking about how to extend my internment crate to support interning of dynamically sized types. I can see how to do this by holding a
&'static T in the
Intern<T>, which is safe and fits with the current implementation.
However, storing a reference to a DST doubles the size of the
Intern<T> for DSTs relative to an optimal implementation, because the reference is a fat pointer which stores both the data and its size. For ordinary references or
Box<T> this is not a problem, but the point of interning your type is to have fast comparison and hashing, under the assumption that you will have many references to the same datum. So storing the size on the heap alongside the data would make a lot more sense than storing the size alongside every pointer to that data.
For individual DST types there tends to be an unsafe
from_raw_parts method that allows to construct a reference from size and pointer. But I'm wondering if there is any way to do so in a correct and sound manner for a generic unsized type?