Skip to content

Commit 7bb9cb7

Browse files
committed
---
yaml --- r: 194332 b: refs/heads/tmp c: 71b9ba1 h: refs/heads/master v: v3
1 parent deba24e commit 7bb9cb7

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
@@ -34,7 +34,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: a3b13610c5b93d9ada072471a001a5613df6a960
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 8b6c0fd410ac118e5159b727f33649af5d5442fa
37+
refs/heads/tmp: 71b9ba1e5b243e52b7c2828e35137eeba378d43f
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3939
refs/tags/homu-tmp: 28a0b25f424090255966273994748a9f9901059f
4040
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412

branches/tmp/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)