Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate metric types with must_use #475

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading