File tree 1 file changed +5
-4
lines changed
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 3
3
The primary way of documenting a Rust project is through annotating the source
4
4
code. Documentation comments are written in [ markdown] and support code
5
5
blocks in them. Rust takes care about correctness, so these code blocks are
6
- compiled and used as tests.
6
+ compiled and used as documentation tests.
7
7
8
8
``` rust,ignore
9
9
/// First line is a short summary describing function.
@@ -48,7 +48,8 @@ pub fn div(a: i32, b: i32) -> i32 {
48
48
}
49
49
```
50
50
51
- Tests can be run with ` cargo test ` :
51
+ Code blocks in documentation are automatically tested
52
+ when running the regular ` cargo test ` command:
52
53
53
54
``` shell
54
55
$ cargo test
@@ -73,8 +74,8 @@ the functionality, which is one of the most important
73
74
[ guidelines] [ question-instead-of-unwrap ] . It allows using examples from docs as
74
75
complete code snippets. But using ` ? ` makes compilation fail since ` main `
75
76
returns ` unit ` . The ability to hide some source lines from documentation comes
76
- to the rescue: one may write ` fn try_main() -> Result<(), ErrorType> ` , hide it and
77
- ` unwrap ` it in hidden ` main ` . Sounds complicated? Here's an example:
77
+ to the rescue: one may write ` fn try_main() -> Result<(), ErrorType> ` , hide it
78
+ and ` unwrap ` it in hidden ` main ` . Sounds complicated? Here's an example:
78
79
79
80
``` rust,ignore
80
81
/// Using hidden `try_main` in doc tests.
You can’t perform that action at this time.
0 commit comments