File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 33The primary way of documenting a Rust project is through annotating the source
44code. Documentation comments are written in [ markdown] and support code
55blocks 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.
77
88``` rust,ignore
99/// First line is a short summary describing function.
@@ -48,7 +48,8 @@ pub fn div(a: i32, b: i32) -> i32 {
4848}
4949```
5050
51- Tests can be run with ` cargo test ` :
51+ Code blocks in documentation are automatically tested
52+ when running the regular ` cargo test ` command:
5253
5354``` shell
5455$ cargo test
@@ -73,8 +74,8 @@ the functionality, which is one of the most important
7374[ guidelines] [ question-instead-of-unwrap ] . It allows using examples from docs as
7475complete code snippets. But using ` ? ` makes compilation fail since ` main `
7576returns ` 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:
7879
7980``` rust,ignore
8081/// Using hidden `try_main` in doc tests.
You can’t perform that action at this time.
0 commit comments