Question about Copy trait

From Constructors - The Rustonomicon

Copy types are implicitly cloned whenever they're moved, but because of the definition of Copy this just means not treating the old copy as uninitialized -- a no-op.

I can't understand "-- a no-op". Which action becomes no-op?

I think what it’s saying is that operations that trigger a copy of a Copy trait would be a move for non-Copy types, which also copies the bytes. The only difference is that, in the move case, the compiler makes the old location inaccessible to your code.

1 Like

"Not treating the old copy as uninitialized" is a no-op. Rephrased, it is a no-op to treat the old copy as initialized.

I think it means that it takes no more work, neither compiler work nor runtime work, to copy a Copy than it takes to move a non-Copy type.

Thanks for replying! I understand what the statement means.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.