Skip to content

Traits Bound Syntax Example: Shouldn't we be using reference? #2172

@apatniv

Description

@apatniv

In chapter ch10-02-traits.md, notify fn is defined as follow:

pub fn notify(item: impl Summary) {
    println!("Breaking news! {}", item.summarize());
}

instead of

pub fn notify(item: &impl Summary) {
    println!("Breaking news! {}", item.summarize());
}

I see the same pattern being used for explaining trait bounds. Is there any particular reason we don't seem to prefer references?

Personally, when I looked at these examples, I started asking questions like

  • why is this defined to move an object?
  • Is author trying to communicate that these methods can only be invoked once. If so, why?

I am more than happy to do the changes if anyone feels in the same manner and it improves readability.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions