[Moving Values] Accessing fields of a borrowed struct instance
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 18.3k
- Forks
- 4.1k
- Avg merge
- 14m
- Merged PRs (30d)
- 1
Description
In Chapter 5 (An Example program using stucts), the example uses a scalar type u32 for the Rectangle struct with this note underneath
... note that accessing fields of a borrowed struct instance does not move the field values, which is why you often see borrows of structs
https://doc.rust-lang.org/book/ch05-02-example-structs.html
I tried to write the Struct and referenced a string in the update_user function as seen in the image below. The compiler raised an error
| ^^^^^^^^^ move occurs because `user.name` has type `String`, which does not implement the `Copy` trait
Is that statement correct or do I not fully understand what it mean? Or does the statement only apply to types that implements the Copy trait? Can anyone explain what the problem is?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Chapter 5 section, then reproduce the update_user example using the borrowed struct and String field described in the issue. Compare the field-access behavior for the documented scalar example and the String case; done means the chapter clearly explains the scope and limitations of the statement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100