Skip to content

Commit

Permalink
lint(metrics/family): add is_empty()
Browse files Browse the repository at this point in the history
```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 <[email protected]>
  • Loading branch information
cratelyn committed Nov 19, 2024
1 parent 27a2e49 commit c301225
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/metrics/family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
self.metrics.read().len()
}

/// Returns `true` if the family contains no metrics.
pub fn is_empty(&self) -> bool {
self.metrics.read().is_empty()
}

pub(crate) fn read(&self) -> RwLockReadGuard<HashMap<S, M>> {
self.metrics.read()
}
Expand Down

0 comments on commit c301225

Please sign in to comment.