How to implement Vec extend_from_within

I was wondering today how I might improve my current implementation, which just has a loop cloning and pushing elements. Especially, I was thinking about using some kind of low-level byte copy where the element type is Copy and not just Clone. If there a way to test if T is Copy and do it one way, otherwise do it another way?

that is called specialization. that is what std does.
you cannot do that in stable code.

ignoring specialization, your implementation could potentially be improved by doing something like what std does in the non-Copy case

Ah, thanks.

Something that seemed odd to me, it uses ptr::copy_nonoverlapping.

But I think the source and destination can overlap. Maybe it somehow "knows" that doesn't matter? If so the comments don't make that clear.

they cannot overlap. the source is a subsection of the already initialized part of the vector, while the destination is the start of the uninitialized part of the vector.

Ah, yes, I was thinking I might be able to use it in a situation where there is overlap, but it doesn't support that.