Unsized enum crate

Following the previous discussion, I've written a crate that provides an unsized enum suitable for my purposes. I've reviewed the Rustonomicon, and some of Ralf's blog posts, and I think it's sound, but I'd appreciate people looking over it. There isn't much code. The documentation page is a good place to start.

As a reminder, the motivating case was a (potential) user of Stakker wanting to do Actor<dyn Trait>, which is problematic because Actor<A> does something along the lines of Rc<SomeCell<enum-of-A-and-other-stuff>>, and enum doesn't support ?Sized right now. Whilst it might seem foolhardy to attempt something "impossible", I've learnt a lot along the way. The unsized_enum crate is like a placemarker for what I need Rust to do for me. As Rust supports ?Sized better, I'll adapt the crate to use those features, and the unsafe review of that crate will hopefully get easier, and at some point it will become uncontroversial to depend on it.

One thing that I realized is that there are two types of unsoundness in Rust: practical unsoundness (i.e. where the optimiser can and will break things) and theoretical unsoundness, where Ralf or whoever is trying to map out the reserved space to give themselves room to manoeuvre later on. Obviously it would be best to respect the theoretical unsoundness too, but right now it is not all settled and fixed.

I've realized that set_v0 could be misused to create a double-free, if someone uses the same &Forget reference twice. But I can get around that by putting a flag in that structure to check whether it has been moved out of yet, to make it safe.

Is there any better way of handling moving an unsized value?

Edit: Okay, I've switched to a Move type which should make it safe. Actually maybe this might need to be changed later to use a Boxed value to handle the coercion required in the calling code, but that doesn't change the fundamental operation being performed by this crate, so shouldn't affect the question of soundness.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.