I have a slice of type
&[u8]. I'd like to convert it to a boxed slice.
One way I can do this is:
let bytes = // a `&[u8]` let mut buf: Vec<u8> = Vec::with_capacity(bytes.len()); buf.extend(bytes); let boxed_slice = buf.into_boxed_slice();
but I think this does 2 copies. It first copies the slice into a vector and then copies the vector into a buffer for the boxed slice.
Is there a way to do this with one copy?