@@ -7,7 +7,7 @@ implementation detail, or leaves readers with unanswered questions.
7
7
8
8
There are a few tenets to Rust documentation that can help guide anyone through
9
9
the process of documenting libraries so that everyone has an ample opportunity
10
- to use the code.
10
+ to use the code.
11
11
12
12
This chapter covers not only how to write documentation but specifically
13
13
how to write ** good** documentation. It is important to be as clear
@@ -19,39 +19,39 @@ then it should be documented.
19
19
20
20
Documenting a crate should begin with front-page documentation. As an
21
21
example, the [ ` hashbrown ` ] crate level documentation summarizes the role of
22
- the crate, provides links to explain technical details, and explains why you
23
- would want to use the crate.
22
+ the crate, provides links to explain technical details, and explains why you
23
+ would want to use the crate.
24
24
25
- After introducing the crate, it is important that the front-page gives
25
+ After introducing the crate, it is important that the front-page gives
26
26
an example of how to use the crate in a real world setting. Stick to the
27
27
library's role in the example, but do so without shortcuts to benefit users who
28
- may copy and paste the example to get started.
28
+ may copy and paste the example to get started.
29
29
30
30
[ ` futures ` ] uses inline comments to explain line by line
31
- the complexities of using a [ ` Future ` ] , because a person's first exposure to
31
+ the complexities of using a [ ` Future ` ] , because a person's first exposure to
32
32
rust's [ ` Future ` ] may be this example.
33
33
34
- The [ ` backtrace ` ] documentation walks through the whole process, explaining
34
+ The [ ` backtrace ` ] documentation walks through the whole process, explaining
35
35
changes made to the ` Cargo.toml ` file, passing command line arguments to the
36
- compiler, and shows a quick example of backtrace in the wild.
36
+ compiler, and shows a quick example of backtrace in the wild.
37
37
38
38
Finally, the front-page can eventually become a comprehensive reference
39
39
how to use a crate, like [ ` regex ` ] . In this front page, all
40
- requirements are outlined, the edge cases shown, and practical examples
40
+ requirements are outlined, the edge cases shown, and practical examples
41
41
provided. The front page goes on to show how to use regular expressions
42
42
then concludes with crate features.
43
43
44
44
Don't worry about comparing your crate, which is just beginning, to other more
45
45
developed crates. To get the documentation to something more polished, start
46
- incrementally and put in an introduction, example, and features. Rome was not
46
+ incrementally and put in an introduction, example, and features. Rome was not
47
47
built in a day!
48
48
49
49
The first lines within the ` lib.rs ` will compose the front-page, and they
50
50
use a different convention than the rest of the rustdocs. Lines should
51
51
start with ` //! ` which indicate module-level or crate-level documentation.
52
52
Here's a quick example of the difference:
53
53
54
- ``` rust,ignore
54
+ ``` rust,no_run
55
55
//! Fast and easy queue abstraction.
56
56
//!
57
57
//! Provides an abstraction over a queue. When the abstraction is used
@@ -64,13 +64,13 @@ Here's a quick example of the difference:
64
64
/// This module makes it easy.
65
65
pub mod easy {
66
66
67
- /// Use the abstract function to do this specific thing.
68
- pub fn abstract () {}
67
+ /// Use the abstraction function to do this specific thing.
68
+ pub fn abstraction () {}
69
69
70
70
}
71
71
```
72
72
73
- Ideally, this first line of documentation is a sentence without highly
73
+ Ideally, this first line of documentation is a sentence without highly
74
74
technical details, but with a good description of where this crate fits
75
75
within the rust ecosystem. Users should know whether this crate meets their use
76
76
case after reading this line.
@@ -95,7 +95,7 @@ It is recommended that each item's documentation follows this basic structure:
95
95
96
96
This basic structure should be straightforward to follow when writing your
97
97
documentation; while you might think that a code example is trivial,
98
- the examples are really important because they can help users understand
98
+ the examples are really important because they can help users understand
99
99
what an item is, how it is used, and for what purpose it exists.
100
100
101
101
Let's see an example coming from the [ standard library] by taking a look at the
@@ -133,7 +133,7 @@ for argument in env::args() {
133
133
[`args_os`]: ./fn.args_os.html
134
134
``````
135
135
136
- Everything before the first empty line will be reused to describe the component
136
+ Everything before the first empty line will be reused to describe the component
137
137
in searches and module overviews. For example, the function ` std::env::args() `
138
138
above will be shown on the [ ` std::env ` ] module documentation. It is good
139
139
practice to keep the summary to one line: concise writing is a goal of good
@@ -163,7 +163,7 @@ interested into taking a look at their website to see what's possible to do.
163
163
[ commonmark markdown specification ] : https://commonmark.org/
164
164
[ commonmark quick reference ] : https://commonmark.org/help/
165
165
[ env::args ] : https://doc.rust-lang.org/stable/std/env/fn.args.html
166
- [ ` Future ` ] : https://doc.rust-lang.org/std/future/trait.Future.html
166
+ [ `Future` ] : https://doc.rust-lang.org/std/future/trait.Future.html
167
167
[ `futures` ] : https://docs.rs/futures/0.3.5/futures/
168
168
[ `hashbrown` ] : https://docs.rs/hashbrown/0.8.2/hashbrown/
169
169
[ `regex` ] : https://docs.rs/regex/1.3.9/regex/
0 commit comments