If I have something similar to an ArrayVec::arrayvec, as I understand it Rust copies all the bits when it is copied or moved. I was wondering if it is possible (or if it even makes sense) to have a custom copy/move function which only copies the initialised elements when moving or copying it.
[ I am not sure this is useful, it is just something I was thinking about, perhaps in a confused way ]
No. Moving/copying a type in rust is always a byte-by-byte copy. The only exception is that rust might or might not copy padding bytes within a struct.
Right. I think it would actually be expressed by a Move trait (I probably should not have mentioned Copy, which is something else).
Currently I guess the compiler could choose to move an Enum type taking into account the current variant, but there is no way to do an “optimised” move where there is a dynamic length. Anyway, thanks for confirming that it isn’t currently possible. As I said it is far from clear to me whether it is useful.