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:
commit
49b4fff348
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user