rust-lang / rust-lang/book

Chapter 5.2 - Taking ownership VS taking reference

Open
#4,571 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
18.3k
Forks
4.1k
Avg merge
14m
Merged PRs (30d)
1

Description

Hi, here in Chapter 5.2 I read that the dbg! macro takes ownership instead of taking reference

https://github.com/rust-lang/book/blob/f78ab89d7545ac17780e6a367055cc089f4cd2ec/src/ch05-02-example-structs.md?plain=1#L196C1-L198C40

and its use is dbg!(&rect1).

However, this seems in contrast with what I read in Chapter 4.2, that for example the function calculate_length takes a reference instead of taking ownership (calculate_length(&s1)).

https://github.com/rust-lang/book/blob/f78ab89d7545ac17780e6a367055cc089f4cd2ec/src/ch04-02-references-and-borrowing.md?plain=1#L12C40-L13C79

Am I misunderstanding how dbg! works or it is also taking a reference (and println! takes ownership instead)?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced passages in src/ch05-02-example-structs.md and src/ch04-02-references-and-borrowing.md, then check the relevant Rust documentation for dbg! and println!. Determine whether the wording creates a contradiction and update the chapter text so the ownership and borrowing behavior is explained consistently.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.