-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add doc comments and doctests to lib.rs
generated by cargo init
#15210
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
Comments
Not a "no" but a "we have to tread carefully":
e.g. in #13371 we shifted that balance a little by making the link for more information transient so there would be less to delete. |
In that vein, what about an |
That still adds an extra step for those users, since they have to remember one more thing. It’s no worse than expanding the template, but I wouldn’t say it’s better either. A flag in Cargo CLI has a more strict stability guarantee than the template itself. Personally, I’m fine with adding a doc comment like this, though I’m not sure where to draw the line on adding more. |
When we discussed this as a team, it was pointed out that the We do have an open question of how much content is appropriate and how to prioritize what to show. We generally lean towards "a screen full" though whose screen is unsure. I did post to https://rust-edu.zulip.cs.pdx.edu/#narrow/stream/75-t-devtools/topic/.60cargo.20new.60.20adding.20doc.20comments.3F/near/80913 to see if I could get feedback from educators. |
My personal preference would be for an empty lib template. Generally, by the time folks start writing lib crates they know what needs to go in them. In terms of the stuff I've taught, I don't teach building lib crates until fairly late, so the template is not all that helpful. All of that said, I think adding a one-line doc comment is probably best if we keep the template. I get diligently following the crate guidelines and providing an example of examples, but I think there's no need to give an example for the |
Is the proposal to have both doctest and
I'd lean toward adding a one-line doc comment, but not adding a test. I think redundancy is too irritating and having a test that doesn't name the function |
The current thought is to add the doctest and keep the |
A big part of why we add the test is to help new users understand that tests exist and are built in. I think there's value in continuing to do that. |
I agree with this. I also think there's considerable value in demonstrating that rustdoc exists and is built in. It really does separate rust from other players (doxygen 😰) |
Any ideas to mitigate the issue of tests being redundant, so that when the |
I use Perhaps the right compromise is to do what was finally (thank you for this) done for the comment link in I that most users using One counterargument is that doctests are currently not run for binary crates by |
Problem
Currently,
lib.rs
generated bycargo init
(orcargo new
) has no doc comments and doctests.cargo/src/cargo/ops/cargo_new.rs
Lines 877 to 880 in 5946db3
I think it would be better if the
add
function had doc comments and doctests. I think these are useful examples of what happens when we runcargo doc
andcargo test
.Proposed Solution
Add doc comments and doctests like this:
Notes
No response
The text was updated successfully, but these errors were encountered: