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 33The ` #[doc] ` attribute lets you control various aspects of how ` rustdoc ` does
44its job.
55
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
88are the same:
99
1010``` rust,ignore
1111/// This is a doc comment.
12- #[doc = "This is a doc comment."]
12+ #[doc = " This is a doc comment."]
1313```
1414
15+ (Note the leading space in the attribute version.)
16+
1517In most cases, ` /// ` is easier to use than ` #[doc] ` . One case where the latter is easier is
1618when generating documentation in macros; the ` collapse-docs ` pass will combine multiple
1719` #[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
2224#[doc = "doc comment"]
2325```
2426
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.
2634
2735The ` doc ` attribute has more options though! These don't involve the text of
2836the output, but instead, various aspects of the presentation of the output.
You can’t perform that action at this time.
0 commit comments