Skip to content

Commit c74dac1

Browse files
committed
---
yaml --- r: 192445 b: refs/heads/auto c: 71b9ba1 h: refs/heads/master i: 192443: 96786ae v: v3
1 parent 9c8ea2a commit c74dac1

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 8b6c0fd410ac118e5159b727f33649af5d5442fa
13+
refs/heads/auto: 71b9ba1e5b243e52b7c2828e35137eeba378d43f
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/trpl/documentation.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,41 @@ By repeating all parts of the example, you can ensure that your example still
333333
compiles, while only showing the parts that are relevant to that part of your
334334
explanation.
335335
336+
### Documenting macros
337+
338+
Here’s an example of documenting a macro:
339+
340+
```
341+
/// Panic with a given message unless an expression evaluates to true.
342+
///
343+
/// # Examples
344+
///
345+
/// ```
346+
/// # #[macro_use] extern crate foo;
347+
/// # fn main() {
348+
/// panic_unless!(1 + 1 == 2, “Math is broken.”);
349+
/// # }
350+
/// ```
351+
///
352+
/// ```should_fail
353+
/// # #[macro_use] extern crate foo;
354+
/// # fn main() {
355+
/// panic_unless!(true == false, “I’m broken.”);
356+
/// # }
357+
/// ```
358+
#[macro_export]
359+
macro_rules! panic_unless {
360+
($condition:expr, $($rest:expr),+) => ({ if ! $condition { panic!($($rest),+); } });
361+
}
362+
```
363+
364+
You’ll note three things: we need to add our own `extern crate` line, so that
365+
we can add the `#[macro_use]` attribute. Second, we’ll need to add our own
366+
`main()` as well. Finally, a judicious use of `#` to comment out those two
367+
things, so they don’t show up in the output.
368+
369+
### Running documentation tests
370+
336371
To run the tests, either
337372
338373
```bash

0 commit comments

Comments
 (0)