Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
apatniv opened this issue Nov 25, 2019 · 3 comments
Closed

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

apatniv opened this issue Nov 25, 2019 · 3 comments
Labels

Comments

@apatniv
Copy link
Contributor

apatniv commented Nov 25, 2019

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.

@apatniv apatniv changed the title Traits Bound Syntax Example: Shouldn't be be using reference? Traits Bound Syntax Example: Shouldn't we be using reference? Nov 25, 2019
@carols10cents
Copy link
Member

Yep, you're right that using references would be better. I think we didn't use them to try to reduce surrounding syntax. I'd accept a change that added references throughout the "traits as parameters" section!

@apatniv
Copy link
Contributor Author

apatniv commented Jan 31, 2020

Ok. I will try to send the update in this week or so.

@steveklabnik
Copy link
Member

I merged the PR, so let's close this. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants