rustdoc allows you to document struct fields and enum variants by including a doc comment above each line:
enum Choices { /// The first choice. First, /// The second choice. Second, } struct Person { /// The person's name. name: String, /// The person's age. age: u8, }
These will show up with nice formatting in the HTML generated by rustdoc. However, I haven't seen any way of making similar nicely-formatted documents for function arguments. Is there an "official" way to document them or do you just have to describe them freeform in the function's main documentation section?
To document functions in Python, use docstrings (triple quotation marks). For example: def greet(name): """ Greets a person with their name.
Information can be passed into functions as arguments. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma.
It is an essential part that documenting your code is going to serve well enough for writing clean code and well-written programs. Docstrings help you understand the capabilities of a module or a function.
To comment on a parameter, start the line with @param , followed by the parameter's name, and then a short description of what the function will do.
I've seen the following style used in some of the examples:
/// Brief. /// /// Description. /// /// * `foo` - Text about foo. /// * `bar` - Text about bar. fn function (foo: i32, bar: &str) {}
So far it's working fine for me too.
P.S. There's also an issue on this.
P.S. Check also the improved rustdoc linking and the search aliases in 1.48.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With