String
& Vec<u8>
are almost the same to me, though String
guarantees to have valid UTF-8 content, which is often useful.
However, being in unsafe context, does it really take any machine operation to cast between two of them if no check is performed?
Consider these two functions:
pub unsafe fn from_utf8_unchecked(bytes: Vec<u8, Global>) -> String
pub fn into_bytes(self) -> Vec<u8, Global>
They're both consuming input, so a compiler has theoretically no need to render a new object in memory.