Struct metriken::DynPinnedMetric
source · pub struct DynPinnedMetric<M>where
M: Metric,{ /* private fields */ }
Expand description
A dynamic metric that stores the metric inline.
This is a dynamic metric that relies on pinning guarantees to ensure that
the stored metric can be safely accessed from other threads looking through
the global dynamic metrics registry. As it requires pinning, it is somewhat
unweildy to use. Most use cases can probably use DynBoxedMetric
instead.
To use this, first create the DynPinnedMetric
and then, once it is pinned,
call register
any number of times with all of the names the metric
should be registered under. When the DynPinnedMetric
instance is dropped
it will unregister all the metric entries added via register
.
§Example
let my_dyn_metric = pin!(DynPinnedMetric::new(Counter::new()));
my_dyn_metric.as_ref().register(MetricBuilder::new("a.dynamic.counter").into_entry());
Implementations§
source§impl<M> DynPinnedMetric<M>where
M: Metric,
impl<M> DynPinnedMetric<M>where
M: Metric,
sourcepub fn new(metric: M) -> DynPinnedMetric<M>
pub fn new(metric: M) -> DynPinnedMetric<M>
Create a new DynPinnedMetric
with the provided internal metric.
This does not register the metric. To do that call register
.
sourcepub fn register(self: Pin<&DynPinnedMetric<M>>, entry: MetricEntry)
pub fn register(self: Pin<&DynPinnedMetric<M>>, entry: MetricEntry)
Register this metric in the global list of dynamic metrics with name
.
Calling this multiple times will result in the same metric being registered multiple times under potentially different names.