File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -217,6 +217,35 @@ spawn(move || { fib(200); })
217
217
The documentation online would look like ` spawn(move || { fib(200); }) ` , but when
218
218
testing this code, the ` fib ` function will be included (so it can compile).
219
219
220
+ Rustdoc will automatically add a ` main() ` wrapper around your code, and in the right
221
+ place. For example:
222
+
223
+ ```
224
+ /// ```
225
+ /// use std::rc::Rc;
226
+ ///
227
+ /// let five = Rc::new(5);
228
+ /// ```
229
+ ```
230
+
231
+ This will end up testing:
232
+
233
+ ```
234
+
235
+ fn main() {
236
+ use std::rc:Rc;
237
+ let five = Rc::new(5);
238
+ }
239
+ ```
240
+
241
+ Here's the full algorithm:
242
+
243
+ 1 . Given a code block, if it does not contain ` fn main ` , it is wrapped in ` fn main() { your_code } `
244
+ 2 . Given that result, if it contains no ` extern crate ` directives but it also
245
+ contains the name of the crate being tested, then ` extern crate <name> ` is
246
+ injected at the top.
247
+ 3 . Some common ` allow ` attributes are added for documentation examples at the top.
248
+
220
249
## Running tests (advanced)
221
250
222
251
Running tests often requires some special configuration to filter tests, find
You can’t perform that action at this time.
0 commit comments