Skip to content

Commit

Permalink
Add an example showing the attribute in use.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Dec 18, 2024
1 parent 6fe508f commit d92a412
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/attributes/coverage-instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ There are two ways to use the coverage attribute:
* `#[coverage(off)]` indicates that all functions within an item, recursively, should not be instrumented, unless specified by another attribute.
* `#[coverage(on)]` (the default) indicates that all functions within an item, recursively, *should* be instrumented, unless specified by another attribute.

```rust
#[coverage(off)]
fn example() {}

struct S;

#[coverage(off)]
impl S {
#[coverage(on)]
fn function_with_coverage() {}

fn function_without_coverage() {}
}
```

r[attributes.coverage.allowed-positions]
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.

Expand Down

0 comments on commit d92a412

Please sign in to comment.