1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::common::ValueHandle;

/// A reference to a [`Counter`].
///
/// A [`Counter`] is used for directly updating a counter, without any lookup overhead.
#[derive(Clone)]
pub struct Counter {
    handle: ValueHandle,
}

impl Counter {
    /// Records a value for the counter.
    pub fn record(&self, value: u64) {
        self.handle.update_counter(value);
    }

    /// Increments the counter by one.
    pub fn increment(&self) {
        self.handle.update_counter(1);
    }
}

impl From<ValueHandle> for Counter {
    fn from(handle: ValueHandle) -> Self {
        Self { handle }
    }
}