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

Add doc comments and doctests to lib.rs generated by cargo init #15210

Open
sorairolake opened this issue Feb 20, 2025 · 1 comment
Open

Add doc comments and doctests to lib.rs generated by cargo init #15210

sorairolake opened this issue Feb 20, 2025 · 1 comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-init Command-new S-triage Status: This issue is waiting on initial triage.

Comments

@sorairolake
Copy link

Problem

Currently, lib.rs generated by cargo init (or cargo new) has no doc comments and doctests.

b"\
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

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 run cargo doc and cargo test.

Proposed Solution

Add doc comments and doctests like this:

/// Calculates `left` + `right`.
///
/// # Examples
///
/// ```
/// let result = add(2, 2);
/// assert_eq!(result, 4);
/// ```
pub fn add(left: u64, right: u64) -> u64 {

Notes

No response

@sorairolake sorairolake added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Feb 20, 2025
@epage
Copy link
Contributor

epage commented Feb 20, 2025

Not a "no" but a "we have to tread carefully": cargo new tries to fill a lot of different roles

  • Teach users about features: where this can be helpful
  • Quickly setup a project: the more users have to delete, the worse this becomes

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-init Command-new S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants