Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Proper location of docstring on struct with attributes
Parent
Proper location of docstring on struct with attributes
When documenting a struct with attributes, where does the docstring go? Before or after the attribute(s)?
Option 1:
/// Does it go here?
#[derive(Deserialize, Debug)]
pub struct Metadata {
pub version: f32,
pub contributors: Vec<String>
}
Option 2:
#[derive(Deserialize, Debug)]
/// Does it go here?
pub struct Metadata {
pub version: f32,
pub contributors: Vec<String>
}
Option 3 (presumably wrong but adding just in case):
#[derive(Deserialize, Debug)]
pub struct Metadata {
/// Does it go here? (I assume this would document `version`,
/// not the struct)
pub version: f32,
pub contributors: Vec<String>
}
Post
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
qohelet | (no comment) | Feb 22, 2024 at 16:49 |
Option 1. The docstring precedes the attributes by convention. Here is an example of the docstring for std::vec::Vec
.
However, if using cargo doc
to generate documentation, it works just fine if you put it after as well.
1 comment thread