Skip to content

Commit d92a412

Browse files
committed
Add an example showing the attribute in use.
1 parent 6fe508f commit d92a412

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/attributes/coverage-instrumentation.md

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ There are two ways to use the coverage attribute:
1919
* `#[coverage(off)]` indicates that all functions within an item, recursively, should not be instrumented, unless specified by another attribute.
2020
* `#[coverage(on)]` (the default) indicates that all functions within an item, recursively, *should* be instrumented, unless specified by another attribute.
2121

22+
```rust
23+
#[coverage(off)]
24+
fn example() {}
25+
26+
struct S;
27+
28+
#[coverage(off)]
29+
impl S {
30+
#[coverage(on)]
31+
fn function_with_coverage() {}
32+
33+
fn function_without_coverage() {}
34+
}
35+
```
36+
2237
r[attributes.coverage.allowed-positions]
2338
The `coverage` attribute can only be controlled at the function level, but it can be applied to modules, `impl` blocks, or anything that can contain functions.
2439

0 commit comments

Comments
 (0)