File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 3
3
The ` #[doc] ` attribute lets you control various aspects of how ` rustdoc ` does
4
4
its job.
5
5
6
- The most basic job of ` #[doc] ` is to be the way that the text of the documentation
7
- is handled . That is, ` /// ` is syntax sugar for ` #[doc] ` . This means that these two
6
+ The most basic function of ` #[doc] ` is to handle the actual documentation
7
+ text . That is, ` /// ` is syntax sugar for ` #[doc] ` . This means that these two
8
8
are the same:
9
9
10
10
``` rust,ignore
11
11
/// This is a doc comment.
12
- #[doc = "This is a doc comment."]
12
+ #[doc = " This is a doc comment."]
13
13
```
14
14
15
+ (Note the leading space in the attribute version.)
16
+
15
17
In most cases, ` /// ` is easier to use than ` #[doc] ` . One case where the latter is easier is
16
18
when generating documentation in macros; the ` collapse-docs ` pass will combine multiple
17
19
` #[doc] ` attributes into a single doc comment, letting you generate code like this:
@@ -22,7 +24,13 @@ when generating documentation in macros; the `collapse-docs` pass will combine m
22
24
#[doc = "doc comment"]
23
25
```
24
26
25
- Which can feel more flexible.
27
+ Which can feel more flexible. Note that this would generate this:
28
+
29
+ ``` rust,ignore
30
+ #[doc = "This is\n a \ndoc comment"]
31
+ ```
32
+
33
+ but given that docs are rendered via Markdown, it will remove these newlines.
26
34
27
35
The ` doc ` attribute has more options though! These don't involve the text of
28
36
the output, but instead, various aspects of the presentation of the output.
You can’t perform that action at this time.
0 commit comments