1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-02 01:36:34 +02:00

Add speaker notes to copy-clone.md

This commit is contained in:
Fabian Bornhofen 2023-01-09 13:20:00 +01:00
parent ba275812aa
commit e213f9dbd3

View File

@ -29,3 +29,20 @@ fn main() {
* After the assignment, both `p1` and `p2` own their own data.
* We can also use `p1.clone()` to explicitly copy the data.
<details>
Copying and cloning are not the same thing:
* Copying refers to bitwise copies of memory regions and does not work on arbitrary objects.
* Cloning is a more general operation and also allows for custom behavior by implementing the `Clone` trait.
* Copying does not work on types that implement the `Drop` trait.
In the above example, try the following:
* Try printing `p1` twice after the move. What do you expect to happen?
* What happens when you add a `String` field to `struct Point`?
* Does it work when you remove `Copy` from the `derive` attribute?
* After removing `Copy`, can you still print `p1` after the move?
</details>