Skip to content

Commit

Permalink
Annotate metric types with must_use
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Apr 26, 2024
1 parent f322087 commit 723237a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions metrics/src/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ pub trait HistogramFn {

/// A counter.
#[derive(Clone)]
#[must_use = "counters do nothing unless you use them"]
pub struct Counter {
inner: Option<Arc<dyn CounterFn + Send + Sync>>,
}

/// A gauge.
#[derive(Clone)]
#[must_use = "gauges do nothing unless you use them"]
pub struct Gauge {
inner: Option<Arc<dyn GaugeFn + Send + Sync>>,
}

/// A histogram.
#[derive(Clone)]
#[must_use = "histograms do nothing unless you use them"]
pub struct Histogram {
inner: Option<Arc<dyn HistogramFn + Send + Sync>>,
}
Expand Down
4 changes: 2 additions & 2 deletions metrics/tests/macros/02_trailing_comma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ fn no_trailing_comma() {

#[allow(dead_code)]
fn with_trailing_comma() {
counter!("qwe",);
counter!("qwe",).increment(1);
counter!(
"qwe",
"qwe",
"foo" => "bar",
).increment(1);
counter!("qwe", vec![],).increment(1);
Expand Down
2 changes: 1 addition & 1 deletion metrics/tests/macros/03_mod_aliasing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use framework::*; // This exposes mod `framework::metrics`.

#[inline]
pub fn register_metrics() {
::metrics::counter!(
let _ = ::metrics::counter!(
metrics::UPLOAD_METRIC_NAME,
&[
(metrics::UPLOAD_METRIC_LABEL_PROCESS_TYPE, ""),
Expand Down

0 comments on commit 723237a

Please sign in to comment.