@@ -16,8 +16,8 @@ The basic idea is this:
16
16
The triple backticks start and end code blocks. If this were in a file named ` foo.rs ` ,
17
17
running ` rustdoc --test foo.rs ` will extract this example, and then run it as a test.
18
18
19
- Please note that by default, if no language is set for the block code, ` rustdoc `
20
- assumes it is ` Rust ` code. So the following:
19
+ Please note that by default, if no language is set for the block code, rustdoc
20
+ assumes it is Rust code. So the following:
21
21
22
22
`````` markdown
23
23
```rust
@@ -44,7 +44,6 @@ the `assert!` family of macros works the same as other Rust code:
44
44
45
45
``` rust
46
46
let foo = " foo" ;
47
-
48
47
assert_eq! (foo , " foo" );
49
48
```
50
49
@@ -55,8 +54,9 @@ the code panics and the doctest fails.
55
54
56
55
In the example above, you'll note something strange: there's no ` main `
57
56
function! Forcing you to write ` main ` for every example, no matter how small,
58
- adds friction. So ` rustdoc ` processes your examples slightly before
59
- running them. Here's the full algorithm rustdoc uses to preprocess examples:
57
+ adds friction and clutters the output. So ` rustdoc ` processes your examples
58
+ slightly before running them. Here's the full algorithm ` rustdoc ` uses to
59
+ preprocess examples:
60
60
61
61
1 . Some common ` allow ` attributes are inserted, including
62
62
` unused_variables ` , ` unused_assignments ` , ` unused_mut ` ,
@@ -78,10 +78,12 @@ Sometimes, you need some setup code, or other things that would distract
78
78
from your example, but are important to make the tests work. Consider
79
79
an example block that looks like this:
80
80
81
- ``` text
81
+ ``` ignore
82
+ /// ```
82
83
/// /// Some documentation.
83
84
/// # fn foo() {} // this function will be hidden
84
85
/// println!("Hello, World!");
86
+ /// ```
85
87
```
86
88
87
89
It will render like this:
@@ -251,7 +253,7 @@ disambiguate the error type:
251
253
This is an unfortunate consequence of the ` ? ` operator adding an implicit
252
254
conversion, so type inference fails because the type is not unique. Please note
253
255
that you must write the ` (()) ` in one sequence without intermediate whitespace
254
- so that rustdoc understands you want an implicit ` Result ` -returning function.
256
+ so that ` rustdoc ` understands you want an implicit ` Result ` -returning function.
255
257
256
258
## Documenting macros
257
259
@@ -359,7 +361,7 @@ the code with the 2015 edition.
359
361
## Syntax reference
360
362
361
363
The * exact* syntax for code blocks, including the edge cases, can be found
362
- in the [ Fenced Code Blocks] ( https://spec.commonmark.org/0.28 /#fenced-code-blocks )
364
+ in the [ Fenced Code Blocks] ( https://spec.commonmark.org/0.29 /#fenced-code-blocks )
363
365
section of the CommonMark specification.
364
366
365
367
Rustdoc also accepts * indented* code blocks as an alternative to fenced
@@ -372,7 +374,7 @@ can indent each line by four or more spaces.
372
374
``````
373
375
374
376
These, too, are documented in the CommonMark specification, in the
375
- [ Indented Code Blocks] ( https://spec.commonmark.org/0.28 /#indented-code-blocks )
377
+ [ Indented Code Blocks] ( https://spec.commonmark.org/0.29 /#indented-code-blocks )
376
378
section.
377
379
378
380
However, it's preferable to use fenced code blocks over indented code blocks.
@@ -388,7 +390,7 @@ documentation. To this end, Rustdoc allows you to have certain items only appear
388
390
collecting doctests, so you can utilize doctest functionality without forcing the test to appear in
389
391
docs, or to find an arbitrary private item to include it on.
390
392
391
- When compiling a crate for use in doctests (with ` --test ` option), rustdoc will set ` cfg(doctest) ` .
393
+ When compiling a crate for use in doctests (with ` --test ` option), ` rustdoc ` will set ` #[ cfg(doctest)] ` .
392
394
Note that they will still link against only the public items of your crate; if you need to test
393
395
private items, you need to write a unit test.
394
396
@@ -407,18 +409,18 @@ pub struct MyStructOnlyTakesUsize;
407
409
```
408
410
409
411
Note that the struct ` MyStructOnlyTakesUsize ` here isn't actually part of your public crate
410
- API. The use of ` #[cfg(doctest)] ` makes sure that this struct only exists while rustdoc is
412
+ API. The use of ` #[cfg(doctest)] ` makes sure that this struct only exists while ` rustdoc ` is
411
413
collecting doctests. This means that its doctest is executed when ` --test ` is passed to rustdoc,
412
414
but is hidden from the public documentation.
413
415
414
- Another possible use of ` cfg(doctest) ` is to test doctests that are included in your README file
416
+ Another possible use of ` #[ cfg(doctest)] ` is to test doctests that are included in your README file
415
417
without including it in your main documentation. For example, you could write this into your
416
418
` lib.rs ` to test your README as part of your doctests:
417
419
418
420
``` rust,ignore
419
421
#![feature(external_doc)]
420
422
421
- #[doc(include= "../README.md")]
423
+ #[doc(include = "../README.md")]
422
424
#[cfg(doctest)]
423
425
pub struct ReadmeDoctests;
424
426
```
0 commit comments