Abomonated is not the only Rust abstraction that relies on slices of bytes Deref-ing into the same location even after a move. Pretty much every attempt at building self-referential types in Rust (which we're kinda doing inside of Abomonated) needs this property. As a result, someone has built the nice stable_deref_trait crate, which provides a trait for exactly this purpose.
We could reduce the unsafety of Abomonated<T, S>::new by requiring S: StableDeref. Unfortunately, we couldn't completely remove the unsafety in this way, because there is still the shared mutability issue to take care of. A long time ago, Rust had a nice Freeze trait for this, but that trait is now gone from the stable subset of the language and there is no sign of it coming back anytime soon. Still, I think partially removing the unsafety is worthwhile.
Using StableDeref would add an extra crate to abomonation's dependency list, but that crate is very small so I don't think it's a big issue.
Abomonated
is not the only Rust abstraction that relies on slices of bytes Deref-ing into the same location even after a move. Pretty much every attempt at building self-referential types in Rust (which we're kinda doing inside of Abomonated) needs this property. As a result, someone has built the nicestable_deref_trait
crate, which provides a trait for exactly this purpose.We could reduce the unsafety of
Abomonated<T, S>::new
by requiringS: StableDeref
. Unfortunately, we couldn't completely remove the unsafety in this way, because there is still the shared mutability issue to take care of. A long time ago, Rust had a niceFreeze
trait for this, but that trait is now gone from the stable subset of the language and there is no sign of it coming back anytime soon. Still, I think partially removing the unsafety is worthwhile.Using
StableDeref
would add an extra crate to abomonation's dependency list, but that crate is very small so I don't think it's a big issue.