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

Make it clear that default traits do not require a separate empty impl block in Section 10.2 #4016

Closed
zkkv opened this issue Aug 19, 2024 · 1 comment

Comments

@zkkv
Copy link

zkkv commented Aug 19, 2024

  • I have searched open and closed issues and pull requests for duplicates, using these search terms:

    • impl
    • 10.2
    • default
  • I have checked the latest main branch to see if this has already been fixed, in this file:

    • src/ch10-02-traits.md

URL to the section(s) of the book with this problem: https://rust-book.cs.brown.edu/ch10-02-traits.html#default-implementations

Description of the problem:
I think the sentence below could be worded better.

To use a default implementation to summarize instances of NewsArticle, we specify an empty impl block with impl Summary for NewsArticle {}.

It can be helpful to emphasize that a trait containing both default and non-implemented methods doesn't require two impl blocks, one of which is empty.

Suggested fix:
The phrasing that could be used:

To use a default implementation to summarize instances of NewsArticle, we must specify an empty impl block with impl Summary for NewsArticle {}, unless there's an existing impl block already.

@chriskrycho
Copy link
Contributor

This is actually covered implicitly just a little ways below, starting at the paragraph which begins “Creating a default implementation doesn’t require us to change anything…” In that section, you will see an impl block for a non-default method which is for the trait. I can imagine ways we could make that more explicit, but I think the text does in fact already cover it. The key is one of sequencing for introducing those ideas, and any sequence we pick will confuse someone. 😉 In any case, I am glad you worked it out!

@chriskrycho chriskrycho closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants