@@ -6,13 +6,13 @@ Use `cargo test` to run all tests (including documentation tests), and `cargo te
66
77These commands will appropriately invoke ` rustdoc ` (and ` rustc ` ) as required.
88
9- ### Doc comments
9+ ## Doc comments
1010
1111Doc comments are very useful for big projects that require documentation. When
1212running ` rustdoc ` , these are the comments that get compiled into
1313documentation. They are denoted by a ` /// ` , and support [ Markdown] .
1414
15- ``` rust,editable,ignore
15+ ```` rust,editable,ignore
1616#![crate_name = "doc"]
1717
1818/// A human being is represented here
@@ -55,7 +55,7 @@ fn main() {
5555
5656 john.hello();
5757}
58- ```
58+ ````
5959
6060To run the tests, first build the code as a library, then tell ` rustdoc ` where
6161to find the library so it can link it into each doctest program:
@@ -65,18 +65,55 @@ $ rustc doc.rs --crate-type lib
6565$ rustdoc --test --extern doc=" libdoc.rlib" doc.rs
6666```
6767
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+ ```
69106
70107### See also:
71108
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 ]
78115
79- [ Markdown ] : https://en.wikipedia.org/wiki/Markdown
116+ [ markdown ] : https://en.wikipedia.org/wiki/Markdown
80117[ book ] : https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments
81118[ ref-comments ] : https://doc.rust-lang.org/stable/reference/comments.html#doc-comments
82119[ rustdoc-book ] : https://doc.rust-lang.org/rustdoc/index.html
0 commit comments