Shallow copy and Bitwise copy

Do shallow copy and Bitwise copy in rust mean the same thing? How should I understand them.

If by "shallow copy" you mean

let y = x;

Then that's either

  • A move of x, if x's type does not implement Copy
    • You can't use x afterwards
  • A copy of x, if x's type implements Copy
    • You can still use x afterwards

And both are bitwise copies (that are almost surely optimized away if you don't use x afterwards).

It’s important to note that in these two examples, the only difference is whether you are allowed to access x after the assignment. Under the hood, both a copy and a move can result in bits being copied in memory, although this is sometimes optimized away.

And from further down:

Copies happen implicitly, for example as part of an assignment y = x. The behavior of Copy is not overloadable; it is always a simple bit-wise copy.


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.