diff options
| author | bors <bors@rust-lang.org> | 2014-07-09 00:36:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-09 00:36:40 +0000 |
| commit | 1c711db551b9a5e56ba76e002e287dcfbb2cff3c (patch) | |
| tree | 6187b19f699c88c1b9bc005165287da6be4f5bd0 /src/doc/guide.md | |
| parent | 206dd91742b43ffa81463e53671afdc412699905 (diff) | |
| parent | 654a19b091c0f05362ee7799355b74c9c1da75ed (diff) | |
| download | rust-1c711db551b9a5e56ba76e002e287dcfbb2cff3c.tar.gz rust-1c711db551b9a5e56ba76e002e287dcfbb2cff3c.zip | |
auto merge of #15374 : steveklabnik/rust/comments, r=brson
I'm leaving off `rustdoc` usage because it won't work unless this is a `pub fn`, and I want to talk about public/private in the context of modules. I'm also not mentioning `//!` because it is exclusively used to provide the overview of a module.
Diffstat (limited to 'src/doc/guide.md')
| -rw-r--r-- | src/doc/guide.md | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/doc/guide.md b/src/doc/guide.md index d2e5d1dbd62..9c136e83c98 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -940,11 +940,54 @@ fn foo(x: int) -> int { There are some additional ways to define functions, but they involve features that we haven't learned about yet, so let's just leave it at that for now. + ## Comments -return +Now that we have some functions, it's a good idea to learn about comments. +Comments are notes that you leave to other programmers to help explain things +about your code. The compiler mostly ignores them. + +Rust has two kinds of comments that you should care about: **line comment**s +and **doc comment**s. + +```{rust} +// Line comments are anything after '//' and extend to the end of the line. + +let x = 5i; // this is also a line comment. + +// If you have a long explanation for something, you can put line comments next +// to each other. Put a space between the // and your comment so that it's +// more readable. +``` + +The other kind of comment is a doc comment. Doc comments use `///` instead of +`//`, and support Markdown notation inside: + +```{rust} +/// `hello` is a function that prints a greeting that is personalized based on +/// the name given. +/// +/// # Arguments +/// +/// * `name` - The name of the person you'd like to greet. +/// +/// # Example +/// +/// ```rust +/// let name = "Steve"; +/// hello(name); // prints "Hello, Steve!" +/// ``` +fn hello(name: &str) { + println!("Hello, {}!", name); +} +``` + +When writing doc comments, adding sections for any arguments, return values, +and providing some examples of usage is very, very helpful. -comments +You can use the `rustdoc` tool to generate HTML documentation from these doc +comments. We will talk more about `rustdoc` when we get to modules, as +generally, you want to export documentation for a full module. ## Compound Data Types |
