Skip to content

Commit c301225

Browse files
committed
lint(metrics/family): add is_empty()
```shell $ cargo clippy --all-features --all-targets --tests Compiling prometheus-client v0.23.0 (/path/to/prometheus-client) warning: struct `Family` has a public `len` method, but no `is_empty` method --> src/metrics/family.rs:309:5 | 309 | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty = note: `#[warn(clippy::len_without_is_empty)]` on by default warning: `prometheus-client` (lib) generated 1 warning warning: `prometheus-client` (lib test) generated 1 warning (1 duplicate) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.63s ``` Signed-off-by: katelyn martin <me+cratelyn@katelyn.world>
1 parent 27a2e49 commit c301225

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/metrics/family.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
310310
self.metrics.read().len()
311311
}
312312

313+
/// Returns `true` if the family contains no metrics.
314+
pub fn is_empty(&self) -> bool {
315+
self.metrics.read().is_empty()
316+
}
317+
313318
pub(crate) fn read(&self) -> RwLockReadGuard<HashMap<S, M>> {
314319
self.metrics.read()
315320
}

0 commit comments

Comments
 (0)