metrics_runtime/data/
counter.rs

1use crate::common::ValueHandle;
2
3/// A reference to a [`Counter`].
4///
5/// A [`Counter`] is used for directly updating a counter, without any lookup overhead.
6#[derive(Clone)]
7pub struct Counter {
8    handle: ValueHandle,
9}
10
11impl Counter {
12    /// Records a value for the counter.
13    pub fn record(&self, value: u64) {
14        self.handle.update_counter(value);
15    }
16
17    /// Increments the counter by one.
18    pub fn increment(&self) {
19        self.handle.update_counter(1);
20    }
21}
22
23impl From<ValueHandle> for Counter {
24    fn from(handle: ValueHandle) -> Self {
25        Self { handle }
26    }
27}