I asked in the Rust Discord channels and it seems like my approach is fine. Even the mutable version is okay and doesn’t need to be unsafe if it returns the reference with self’s lifetime.
Then maybe publish it as a mini-crate (e.g. any-slice
), ideally with a link to the discussion that proves that it is sound.
Playground link is mangled as well: I needed to manually replace
&
s with&
to make it load the gist.