diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-23 15:11:00 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-23 15:11:00 -0700 |
| commit | a78eb530746051f772b0e9f258ea7c4da976ed21 (patch) | |
| tree | 1780b1922d30bfb7f7b54b9f9d8bd7913be7af4f /src | |
| parent | 5a6a90508d0ea00c89507f762d08abb7f2c444d5 (diff) | |
| parent | fbc823d1e337e546b5bf7e6fc53f26b51a8583f2 (diff) | |
rollup merge of #23618: steveklabnik/gh23571
Fixes #23571
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/trpl/documentation.md | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index 8e5b3b6a7f0..7300753cc66 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -333,6 +333,41 @@ By repeating all parts of the example, you can ensure that your example still compiles, while only showing the parts that are relevant to that part of your explanation. +### Documenting macros + +Here’s an example of documenting a macro: + +``` +/// Panic with a given message unless an expression evaluates to true. +/// +/// # Examples +/// +/// ``` +/// # #[macro_use] extern crate foo; +/// # fn main() { +/// panic_unless!(1 + 1 == 2, “Math is broken.”); +/// # } +/// ``` +/// +/// ```should_fail +/// # #[macro_use] extern crate foo; +/// # fn main() { +/// panic_unless!(true == false, “I’m broken.”); +/// # } +/// ``` +#[macro_export] +macro_rules! panic_unless { + ($condition:expr, $($rest:expr),+) => ({ if ! $condition { panic!($($rest),+); } }); +} +``` + +You’ll note three things: we need to add our own `extern crate` line, so that +we can add the `#[macro_use]` attribute. Second, we’ll need to add our own +`main()` as well. Finally, a judicious use of `#` to comment out those two +things, so they don’t show up in the output. + +### Running documentation tests + To run the tests, either ```bash |
