@@ -20,6 +20,7 @@ comments":
20
20
//! the crate index page. The ! makes it apply to the parent of the comment,
21
21
//! rather than what follows).
22
22
23
+ # mod workaround_the_outer_function_rustdoc_inserts {
23
24
/// Widgets are very common (this is a doc comment, and will show up on
24
25
/// Widget's documentation).
25
26
pub struct Widget {
@@ -36,6 +37,7 @@ pub fn recalibrate() {
36
37
//! `recalibrate`).
37
38
/* ... */
38
39
}
40
+ # }
39
41
~~~
40
42
41
43
Doc comments are markdown, and are currently parsed with the
@@ -94,7 +96,7 @@ source code.
94
96
95
97
To test documentation, the ` --test ` argument is passed to rustdoc:
96
98
97
- ~~~
99
+ ~~~ {.notrust}
98
100
rustdoc --test crate.rs
99
101
~~~
100
102
@@ -105,56 +107,68 @@ code blocks as testable-by-default. In order to not run a test over a block of
105
107
code, the ` ignore ` string can be added to the three-backtick form of markdown
106
108
code block.
107
109
108
- ~~~
109
- ```
110
- // This is a testable code block
111
- ```
110
+ /**
111
+ # nested codefences confuse sundown => indentation + comment to
112
+ # avoid failing tests
113
+ ```
114
+ // This is a testable code block
115
+ ```
112
116
113
- ```ignore
114
- // This is not a testable code block
115
- ```
117
+ ```ignore
118
+ // This is not a testable code block
119
+ ```
116
120
117
- // This is a testable code block (4-space indent)
118
- ~~~
121
+ // This is a testable code block (4-space indent)
122
+ */
123
+ # fn foo() {}
119
124
120
125
You can specify that the test's execution should fail with the ` should_fail `
121
126
directive.
122
127
123
- ~~~
124
- ```should_fail
125
- // This code block is expected to generate a failure when run
126
- ```
127
- ~~~
128
+ /**
129
+ # nested codefences confuse sundown => indentation + comment to
130
+ # avoid failing tests
131
+ ```should_fail
132
+ // This code block is expected to generate a failure when run
133
+ ```
134
+ */
135
+ # fn foo() {}
128
136
129
137
You can specify that the code block should be compiled but not run with the
130
138
` no_run ` directive.
131
139
132
- ~~~
133
- ```no_run
134
- // This code will be compiled but not executed
135
- ```
136
- ~~~
140
+ /**
141
+ # nested codefences confuse sundown => indentation + comment to
142
+ # avoid failing tests
143
+ ```no_run
144
+ // This code will be compiled but not executed
145
+ ```
146
+ */
147
+ # fn foo() {}
137
148
138
149
Rustdoc also supplies some extra sugar for helping with some tedious
139
150
documentation examples. If a line is prefixed with ` # ` , then the line
140
151
will not show up in the HTML documentation, but it will be used when
141
152
testing the code block (NB. the space after the ` # ` is required, so
142
153
that one can still write things like ` #[deriving(Eq)] ` ).
143
154
144
- ~~~
145
- ```rust
146
- # /!\ The three following lines are comments, which are usually stripped off by
147
- # the doc-generating tool. In order to display them anyway in this particular
148
- # case, the character following the leading '#' is not a usual space like in
149
- # these first five lines but a non breakable one.
150
- #
151
- # // showing 'fib' in this documentation would just be tedious and detracts from
152
- # // what's actualy being documented.
153
- # fn fib(n: int) { n + 2 }
154
-
155
- do spawn { fib(200); }
156
- ```
157
- ~~~
155
+ /**
156
+ # nested codefences confuse sundown => indentation + comment to
157
+ # avoid failing tests
158
+ ```rust
159
+ # /!\ The three following lines are comments, which are usually stripped off by
160
+ # the doc-generating tool. In order to display them anyway in this particular
161
+ # case, the character following the leading '#' is not a usual space like in
162
+ # these first five lines but a non breakable one.
163
+ #
164
+ # // showing 'fib' in this documentation would just be tedious and detracts from
165
+ # // what's actualy being documented.
166
+ # fn fib(n: int) { n + 2 }
167
+
168
+ do spawn { fib(200); }
169
+ ```
170
+ */
171
+ # fn foo() {}
158
172
159
173
The documentation online would look like ` do spawn { fib(200); } ` , but when
160
174
testing this code, the ` fib ` function will be included (so it can compile).
@@ -167,12 +181,12 @@ uses is build on crate `test`, which is also used when you compile crates with
167
181
rustc's ` --test ` flag. Extra arguments can be passed to rustdoc's test harness
168
182
with the ` --test-args ` flag.
169
183
170
- ~~~
171
- // Only run tests containing 'foo' in their name
172
- rustdoc --test lib.rs --test-args 'foo'
184
+ ~~~ {.notrust}
185
+ $ # Only run tests containing 'foo' in their name
186
+ $ rustdoc --test lib.rs --test-args 'foo'
173
187
174
- // See what's possible when running tests
175
- rustdoc --test lib.rs --test-args '--help'
188
+ $ # See what's possible when running tests
189
+ $ rustdoc --test lib.rs --test-args '--help'
176
190
~~~
177
191
178
192
When testing a library, code examples will often show how functions are used,
@@ -189,6 +203,7 @@ into HTML and testing the code snippets from them. A Markdown file is
189
203
detected by a ` .md ` or ` .markdown ` extension.
190
204
191
205
There are 4 options to modify the output that Rustdoc creates.
206
+
192
207
- ` --markdown-css PATH ` : adds a ` <link rel="stylesheet"> ` tag pointing to ` PATH ` .
193
208
- ` --markdown-in-header FILE ` : includes the contents of ` FILE ` at the
194
209
end of the ` <head>...</head> ` section.
0 commit comments