Commit 720ca4a
committed
feat: Add
This prevents code like the following from compiling:
```rust
meter
.i64_observable_up_down_counter("my_counter")
.with_callback(|observer| {
observer.observe(1, &[]);
});
```
This code is missing the `.build()` at the end. Before this commit, it would
compile, but the callback would never be called. After this commit, it will
cause a mostly helpful compile error:
```
warning: unused `AsyncInstrumentBuilder` that must be used
--> examples/metrics-basic/src/main.rs:71:5
|
71 | / meter
72 | | .i64_observable_up_down_counter("my_counter")
73 | | .with_callback(|observer| {
74 | | observer.observe(1, &[]);
75 | | });
| |__________^
|
= note: AsyncInstrumentBuilder must be built to receive callbacks.
= note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
|
71 | let _ = meter
| +++++++
```
Most builders need to be built to be useful. Normal metrics are built and then
observations are reported to them, where a failure to call `build()` would be
discovered at compile-time. However, observable metrics (async instruments)
don't have that natural use point, as the result of building an
`AsyncInstrumentBuilder` isn't typically needed. This makes
`AsyncInstrumentBuilder` especially error-prone without the `#[must_use]`
declaration.#[must_use] to AsyncInstrumentBuilder1 parent 95af815 commit 720ca4a
1 file changed
+1
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
| |||
0 commit comments