Skip to content

Commit 40d369a

Browse files
committed
API comment conventions
1 parent 44e3043 commit 40d369a

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
- Start Date: 2014-12-08
2+
- RFC PR: (leave this empty)
3+
- Rust Issue: (leave this empty)
4+
5+
# Summary
6+
7+
This is a conventions RFC, providing guidance on providing API documentation
8+
for Rust projects, including the Rust language itself.
9+
10+
# Motivation
11+
12+
Documentation is an extremely important part of any project. It's important
13+
that we have consistency in our documentation.
14+
15+
For the most part, the RFC proposes guidelines that are already followed today,
16+
but it tries to motivate and clarify them.
17+
18+
# Detailed design
19+
20+
There are a number of indivudal guidelines:
21+
22+
## Use line comments
23+
24+
Avoid block comments. Use line comments instead:
25+
26+
```rust
27+
// Wait for the main task to return, and set the process error code
28+
// appropriately.
29+
```
30+
31+
Instead of:
32+
33+
```rust
34+
/*
35+
* Wait for the main task to return, and set the process error code
36+
* appropriately.
37+
*/
38+
```
39+
40+
Only use inner doc comments //! to write crate and module-level documentation, nothing else.
41+
42+
## Formatting
43+
44+
The first line in any doc comment should be a single-line short sentence
45+
providing a summary of the code. This line is used as a summary description
46+
throughout Rustdoc's output, so it's a good idea to keep it short.
47+
48+
All doc comments, including the summary line, should begin with a capital
49+
letter and end with a period, question mark, or exclamation point. Prefer full
50+
sentences to fragments.
51+
52+
The summary line should be written in third person singular present indicative
53+
form. Basically, this means write "Returns" instead of "Return".
54+
55+
## Using Markdown
56+
57+
Within doc comments, use Markdown to format your documentation.
58+
59+
Use top level headings # to indicate sections within your comment. Common headings:
60+
61+
* Examples
62+
* Panics
63+
* Failure
64+
65+
Even if you only include one example, use the plural form: "Examples" rather
66+
than "Example". Future tooling is easier this way.
67+
68+
Use graves (`) to denote a code fragment within a sentence.
69+
70+
Use triple graves (```) to write longer examples, like this:
71+
72+
This code does something cool.
73+
74+
```rust
75+
let x = foo();
76+
x.bar();
77+
```
78+
79+
When appropriate, make use of Rustdoc's modifiers. Annotate triple grave blocks with
80+
the appropriate formatting directive. While they default to Rust in Rustdoc, prefer
81+
being explicit, so that it highlights syntax in places that do not, like GitHub.
82+
83+
```rust
84+
println!("Hello, world!");
85+
```
86+
87+
```ruby
88+
puts "Hello"
89+
```
90+
91+
Rustdoc is able to test all Rust examples embedded inside of documentation, so
92+
it's important to mark what is not Rust so your tests don't fail.
93+
94+
References and citation should be linked inline. Prefer
95+
96+
```
97+
[some paper](http://www.foo.edu/something.pdf)
98+
```
99+
100+
to
101+
102+
```
103+
some paper[1]
104+
105+
1: http://www.foo.edu/something.pdf
106+
```
107+
108+
## English
109+
110+
All documentation is standardized on American English, with regards to
111+
spelling, grammar, and punctuation conventions. Language changes over time,
112+
so this doesn't mean that there is always a correct answer to every grammar
113+
question, but there is often some kind of formal consensus.
114+
115+
# Drawbacks
116+
117+
None.
118+
119+
# Alternatives
120+
121+
Not having documentation guidelines.
122+
123+
# Unresolved questions
124+
125+
None.

0 commit comments

Comments
 (0)