diff --git a/src/ore/src/metrics/delete_on_drop.rs b/src/ore/src/metrics/delete_on_drop.rs index 6f7fb99cdbe7d..fd2cf9f92aa09 100644 --- a/src/ore/src/metrics/delete_on_drop.rs +++ b/src/ore/src/metrics/delete_on_drop.rs @@ -27,6 +27,7 @@ //! * When using owned data (an extension over what Prometheus allows, which only lets you use //! references to refer to labels), the created metric is also allowed to live for `'static`. +use std::borrow::Borrow; use std::collections::BTreeMap; use std::marker::PhantomData; use std::ops::Deref; @@ -149,6 +150,10 @@ impl<'a> PromLabelsExt<'a> for BTreeMap<&'a str, &'a str> { /// /// It adds a method to create a concrete metric from the vector that gets removed from the vector /// when the concrete metric is dropped. +/// +/// NOTE: This type implements [`Borrow`], which imposes some constraints on implementers. To +/// ensure these constraints, do *not* implement any of the `Eq`, `Ord`, or `Hash` traits on this. +/// type. #[derive(Debug)] pub struct DeleteOnDropHistogram<'a, L> where @@ -185,6 +190,15 @@ where } } +impl<'a, L> Borrow for DeleteOnDropHistogram<'a, L> +where + L: PromLabelsExt<'a>, +{ + fn borrow(&self) -> &Histogram { + &self.inner + } +} + impl<'a, L> Drop for DeleteOnDropHistogram<'a, L> where L: PromLabelsExt<'a>, @@ -200,6 +214,10 @@ where /// /// It adds a method to create a concrete metric from the vector that gets removed from the vector /// when the concrete metric is dropped. +/// +/// NOTE: This type implements [`Borrow`], which imposes some constraints on implementers. To +/// ensure these constraints, do *not* implement any of the `Eq`, `Ord`, or `Hash` traits on this. +/// type. #[derive(Debug)] pub struct DeleteOnDropCounter<'a, P, L> where @@ -239,6 +257,16 @@ where } } +impl<'a, P, L> Borrow> for DeleteOnDropCounter<'a, P, L> +where + P: Atomic, + L: PromLabelsExt<'a>, +{ + fn borrow(&self) -> &GenericCounter

{ + &self.inner + } +} + impl<'a, P, L> Drop for DeleteOnDropCounter<'a, P, L> where P: Atomic, @@ -301,6 +329,10 @@ impl HistogramVecExt for HistogramVec { } /// A [`GenericGauge`] wrapper that deletes its labels from the vec when it is dropped +/// +/// NOTE: This type implements [`Borrow`], which imposes some constraints on implementers. To +/// ensure these constraints, do *not* implement any of the `Eq`, `Ord`, or `Hash` traits on this. +/// type. #[derive(Debug)] pub struct DeleteOnDropGauge<'a, P, L> where @@ -340,6 +372,16 @@ where } } +impl<'a, P, L> Borrow> for DeleteOnDropGauge<'a, P, L> +where + P: Atomic, + L: PromLabelsExt<'a>, +{ + fn borrow(&self) -> &GenericGauge

{ + &self.inner + } +} + impl<'a, P, L> Drop for DeleteOnDropGauge<'a, P, L> where P: Atomic,