@@ -6,13 +6,13 @@ Use `cargo test` to run all tests (including documentation tests), and `cargo te
6
6
7
7
These commands will appropriately invoke ` rustdoc ` (and ` rustc ` ) as required.
8
8
9
- ### Doc comments
9
+ ## Doc comments
10
10
11
11
Doc comments are very useful for big projects that require documentation. When
12
12
running ` rustdoc ` , these are the comments that get compiled into
13
13
documentation. They are denoted by a ` /// ` , and support [ Markdown] .
14
14
15
- ``` rust,editable,ignore
15
+ ```` rust,editable,ignore
16
16
#![crate_name = "doc"]
17
17
18
18
/// A human being is represented here
@@ -55,7 +55,7 @@ fn main() {
55
55
56
56
john.hello();
57
57
}
58
- ```
58
+ ````
59
59
60
60
To run the tests, first build the code as a library, then tell ` rustdoc ` where
61
61
to find the library so it can link it into each doctest program:
@@ -65,18 +65,55 @@ $ rustc doc.rs --crate-type lib
65
65
$ rustdoc --test --extern doc=" libdoc.rlib" doc.rs
66
66
```
67
67
68
- For documentation, ` rustdoc ` is widely used by the community. It's what is used to generate the [ std library docs] ( https://doc.rust-lang.org/std/ ) .
68
+ ## Doc attributes
69
+
70
+ Below are a few examples of the most common ` #[doc] ` attributes used with ` rustdoc ` .
71
+
72
+ ### ` inline `
73
+
74
+ Used to inline docs, instead of linking out to separate page.
75
+
76
+ ``` rust
77
+ #[doc(inline)]
78
+ pub use bar :: Bar ;
79
+
80
+ /// bar docs
81
+ mod bar {
82
+ /// the docs for Bar
83
+ pub struct Bar ;
84
+ }
85
+ ```
86
+
87
+ ### ` no_inline `
88
+
89
+ Used to prevent linking out to separate page or anywhere.
90
+
91
+ ``` rust
92
+ // Example from libcore/prelude
93
+ #[doc(no_inline)]
94
+ pub use crate :: mem :: drop;
95
+ ```
96
+
97
+ ### ` hidden `
98
+
99
+ Using this tells ` rustdoc ` not to include this in documentation:
100
+
101
+ ``` rust,editable
102
+ // Example from the futures-rs library
103
+ #[doc(hidden)]
104
+ pub use self::async_await::*;
105
+ ```
69
106
70
107
### See also:
71
108
72
- * [ The Rust Book: Making Useful Documentation Comments] [ book ]
73
- * [ The rustdoc Book] [ rustdoc-book ]
74
- * [ The Reference: Doc comments] [ ref-comments ]
75
- * [ RFC 1574: API Documentation Conventions] [ api-conv ]
76
- * [ RFC 1946: Relative links to other items from doc comments (intra-rustdoc links)] [ intra-links ]
77
- * [ Is there any documentation style guide for comments? (reddit)] [ reddit ]
109
+ - [ The Rust Book: Making Useful Documentation Comments] [ book ]
110
+ - [ The rustdoc Book] [ rustdoc-book ]
111
+ - [ The Reference: Doc comments] [ ref-comments ]
112
+ - [ RFC 1574: API Documentation Conventions] [ api-conv ]
113
+ - [ RFC 1946: Relative links to other items from doc comments (intra-rustdoc links)] [ intra-links ]
114
+ - [ Is there any documentation style guide for comments? (reddit)] [ reddit ]
78
115
79
- [ Markdown ] : https://en.wikipedia.org/wiki/Markdown
116
+ [ markdown ] : https://en.wikipedia.org/wiki/Markdown
80
117
[ book ] : https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments
81
118
[ ref-comments ] : https://doc.rust-lang.org/stable/reference/comments.html#doc-comments
82
119
[ rustdoc-book ] : https://doc.rust-lang.org/rustdoc/index.html
0 commit comments