let src = [1, 2, 3, 4];
let mut dst = [0, 0];
// Because the slices have to be the same length,
// we slice the source slice from four elements
// to two. It will panic if we don't do this.
dst.copy_from_slice(&src[2..]);
I'm exchanging packets back and forth between tcp client and server. The first 64 bytes of the message are used for header. The content of the header may varies in size in this range.
In the server side I'll go through the header of the message looking for the first nullbyte with indicates the length of it, so I can read it peacefully.
Ideally in the client I'll create a fixed size vec, fill it with 64 nullbytes and copy the actual content to it, leaving the rest of null bytes behind.
copy_from_slice requires both vecs to be the same size, which is something that I cannot guarantee.