Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you document function arguments?

Tags:

rust

rustdoc

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?

like image 758
Jimmy Avatar asked May 03 '15 02:05

Jimmy


People also ask

How do you document a function in Python?

To document functions in Python, use docstrings (triple quotation marks). For example: def greet(name): """ Greets a person with their name.

How do you write arguments in Python?

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.

Why are docstrings important in the documentation of functions?

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.

How do you comment parameters?

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.


1 Answers

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.

like image 124
ArtemGr Avatar answered Sep 20 '22 11:09

ArtemGr