-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
rustdoc: Add option to hide imports from rendered examples #109121
Comments
Transferred to rust-lang/rust as this sounds like a rustdoc issue, and that is where rustdoc issues are tracked. |
you can already do this today: https://doc.rust-lang.org/beta/rustdoc/write-documentation/documentation-tests.html#hiding-portions-of-the-example if you want a button that users can click to show or hide it, that's harder, but i'm not sure why it would be useful? |
This sounds like a Curse of Knowledge issue :-D. Doc authors hide imports because the needed imports are obvious to the author, but they are sometimes not obvious to the reader. It would probably be good to add to the rustdoc book, under the "How to write documentation > What to include (and exclude) > Examples" section, a recommendation to include any necessary |
This helps users to understand examples quickly without getting distracted by imports while still providing an option to copy a fully working code example if they decide to use it. |
I had a PR which proposed this change a while ago: #86892 |
Problem
Adding imports to code examples are necessary to make them compile however it makes code examples more hard to read. That's why many developers choose to hide them from the generated output. This leads to the problem that when copying code examples users have to manually choose the correct imports which can be error-prone.
Proposed Solution
Add an UI option to each Rust code block that allows to dynamically hide and show the imports.
Notes
This may raise the question if we also want an option to show/hide all hidden code fragments.
The text was updated successfully, but these errors were encountered: