1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-02-04 10:09:29 +02:00

Merge pull request #131 from fbornhofen/main

Add speaker notes to copy-clone.md
This commit is contained in:
Andrew Walbran 2023-01-09 13:05:02 +00:00 committed by GitHub
commit 49b4fff348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,3 +29,19 @@ fn main() {
* After the assignment, both `p1` and `p2` own their own data. * After the assignment, both `p1` and `p2` own their own data.
* We can also use `p1.clone()` to explicitly copy the 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:
* 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>