1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Include Rust source files as doctests.
//!
//! # Examples
//!
//! ## Using [`source_file!`]
//!
//! We'll write our example in the file `examples/my_example.rs`, and use
//! [`source_file!`] to add the example to our documentation. The contents of
//! `examples/my_example.rs` are:
//!
//! ```
//! ```
//!
//! Using `#[doc = source_file!("examples/my_example.rs")]` will hide imports and
//! include the body of the main function, leaving us with:
//! ```
//! ```
//!
//! ## Using [`function_body!`]
//!
//! [`function_body!`] is similar to [`source_file!`], but allows us to specify which
//! function body to use as the doctest. This reduces boilerplate for imports
//! and supporting code, as we can put many examples in one file. We can
//! also specify which parts of the supporting code to include.
//!
//! Usage is:
//! ```
//! include_doc::function_body!(
//! "example.rs",
//! example_fn,
//! [fn_dependency, StructDependency, etc]
//! );
//! ```
//!
//! In `tests/doc.rs`, we've put 2 examples, `my_first_example` and `my_second_example`.
//! There are 2 different setup functions, but both use `MyStruct`. Here's the contents of
//! `tests/doc.rs`:
//! ```
//! ```
//!
//! We want to include only the example code and dependencies for
//! `my_first_example`, so we write
//! `#[doc = function_body!("tests/doc.rs", my_first_example, [MyStruct, setup_first_example])]`,
//! giving us:
//! ```
)]
//! ```
//!
//! For `my_second_example`, we use
//! `#[doc = function_body!("tests/doc.rs", my_second_example, [MyStruct, setup_second_example])]`,
//! giving:
//! ```
)]
//! ```
/// Include the function body from a Rust file as a doctest.
///
/// See [module][self] documentation.
pub use function_body;
/// Include a Rust file as a doctest.
///
/// See [module][self] documentation.
pub use source_file;