mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-04 11:39:42 +02:00
Add speaker notes for moves-function-calls.md
This commit is contained in:
parent
ddd68c5b0f
commit
9c652d06aa
@ -14,3 +14,12 @@ fn main() {
|
||||
// say_hello(name);
|
||||
}
|
||||
```
|
||||
|
||||
<details>
|
||||
|
||||
* With the first call to `say_hello`, `main` gives up ownership of `name`. Afterwards, `name` cannot be used anymore within `main`.
|
||||
* `main` can retain ownership if it passes `name` as a reference (`&name`) and if `say_hello` accepts a reference as a parameter.
|
||||
* Alternatively, `main` can pass a clone of `name` in the first call (`name.clone()`).
|
||||
* Rust makes it harder than C++ to inadvertently create copies by making move semantics the default, and by forcing programmers to make clones explicit.
|
||||
|
||||
</details>
|
||||
|
Loading…
Reference in New Issue
Block a user