1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-09 09:11:50 +02:00

Update moves-function-calls.md (#220)

Additional note helps to understand what move really means. The `name` ownership went fully into the `say_hello`.
This commit is contained in:
Igor Petruk 2023-01-23 11:23:44 +00:00 committed by GitHub
parent 8c58253217
commit de4aa3de88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ fn main() {
<details>
* With the first call to `say_hello`, `main` gives up ownership of `name`. Afterwards, `name` cannot be used anymore within `main`.
* The heap memory allocated for `name` will be freed at the end of the `say_hello` function.
* `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.