这是indexloc提供的服务,不要输入任何密码
Skip to content

Chapter 5.2 - Taking ownership VS taking reference #4571

@andrea-petrocchi

Description

@andrea-petrocchi

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)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions