This would be allowed with
slice::from_raw_parts, as that one is more explicit about its interaction with reinterpreting memory.
I think the correct interpretation is that the
Vec::from_raw_parts documentation itself does not allow this. However, given the guarantees provided for
Vec's structure/layout, I think this is effectively guaranteed to work.
The tricky part, ofc, is that while
Vec<[u8; 2]> -> Vec<u8> is rather simple (half element size, double capacity and length), the reverse direction is a lot harder, as you have to ensure that the capacity evenly divides into the new type.
(And just a reminder for readers: alignment must stay the same when owning an allocation, and may not be changed in any way.)