2

When writing Rust documentation tests, is it possible to externalize parts of the code to an external file to keep the example short?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • *why?* If the code is relevant to the example, show it. If it's not relevant to the example, just [prefix the lines with `#` to hide them](https://doc.rust-lang.org/stable/book/first-edition/documentation.html): *you can add lines that start with `#`, and they will be hidden from the output, but will be used when compiling your code* – Shepmaster Jul 18 '17 at 12:31
  • I was thinking that I could extract non relevant parts into that file. Otherwise it will boat up the documentation to only be readable when rendered. – Krampenschiesser Jul 18 '17 at 15:48

2 Answers2

3

# include!("src/fragment.rs") appears to work and does not show up in the output. I have no idea how this interferes with Cargo's dependency processing, though.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
1

I don't think it is officially supported at this moment; there is a related Cargo issue and a tool that attempts to allow it until it is introduced in Cargo (I haven't used it, though).

ljedrz
  • 20,316
  • 4
  • 69
  • 97