Skip to content

Commit 2e02f22

Browse files
authored
Merge pull request #1981 from darkdevil3610/master
docs(comments): improve readability and formatting
2 parents dc6a0ad + ad6ee3d commit 2e02f22

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/hello/comment.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,52 @@
33
Any program requires comments, and Rust supports
44
a few different varieties:
55

6-
* *Regular comments* which are ignored by the compiler:
7-
* `// Line comments which go to the end of the line.`
8-
* `/* Block comments which go to the closing delimiter. */`
9-
* *Doc comments* which are parsed into HTML library [documentation][docs]:
10-
* `/// Generate library docs for the following item.`
11-
* `//! Generate library docs for the enclosing item.`
6+
## Regular Comments
127

8+
These are ignored by the compiler:
9+
10+
* **Line comments**: Start with `//` and continue to the end of the line
11+
* **Block comments**: Enclosed in `/* ... */` and can span multiple lines
12+
13+
## Documentation Comments (Doc Comments) which are parsed into HTML library [documentation][docs]:
14+
15+
- `///` - Generates docs for the item that follows it
16+
- `//!` - Generates docs for the enclosing item (typically used at the top of a file or module)
1317
```rust,editable
18+
1419
fn main() {
15-
// This is an example of a line comment.
16-
// There are two slashes at the beginning of the line.
17-
// And nothing written after these will be read by the compiler.
20+
// Line comments start with two slashes.
21+
// Everything after the slashes is ignored by the compiler.
1822
23+
// Example: This line won't execute
1924
// println!("Hello, world!");
2025
21-
// Run it. See? Now try deleting the two slashes, and run it again.
26+
// Try removing the slashes above and running the code again.
2227
2328
/*
24-
* This is another type of comment, a block comment. In general,
25-
* line comments are the recommended comment style. But block comments
26-
* are extremely useful for temporarily disabling chunks of code.
27-
* /* Block comments can be /* nested, */ */ so it takes only a few
28-
* keystrokes to comment out everything in this main() function.
29-
* /*/*/* Try it yourself! */*/*/
29+
* Block comments are useful for temporarily disabling code.
30+
* They can also be nested: /* like this */ which makes it easy
31+
* to comment out large sections quickly.
3032
*/
3133
3234
/*
33-
Note: The previous column of `*` was entirely for style. There's
34-
no actual need for it.
35+
Note: The asterisk column on the left is just for style -
36+
it's not required by the language.
3537
*/
3638
37-
// Here's another powerful use of block comments: you can uncomment
38-
// and comment a whole block by simply adding or removing a single
39-
// '/' character:
39+
// Block comments make it easy to toggle code on/off by adding
40+
// or removing just one slash:
4041
41-
/* <- add another '/' before the 1st one to uncomment the whole block
42+
/* <- Add a '/' here to uncomment the entire block below
4243
4344
println!("Now");
4445
println!("everything");
4546
println!("executes!");
46-
// line comments inside are not affected by either state
47+
// Line comments inside remain unaffected
4748
4849
// */
4950
50-
// You can manipulate expressions more easily with block comments
51-
// than with line comments. Try deleting the comment delimiters
52-
// to change the result:
51+
// Block comments can also be used within expressions:
5352
let x = 5 + /* 90 + */ 5;
5453
println!("Is `x` 10 or 100? x = {}", x);
5554
}

0 commit comments

Comments
 (0)