metrics_util/registry/
storage.rsuse std::sync::Arc;
use metrics::{atomics::AtomicU64, CounterFn, GaugeFn, HistogramFn};
use crate::AtomicBucket;
pub trait Storage<K> {
type Counter: CounterFn + Clone;
type Gauge: GaugeFn + Clone;
type Histogram: HistogramFn + Clone;
fn counter(&self, key: &K) -> Self::Counter;
fn gauge(&self, key: &K) -> Self::Gauge;
fn histogram(&self, key: &K) -> Self::Histogram;
}
#[derive(Debug)]
pub struct AtomicStorage;
impl<K> Storage<K> for AtomicStorage {
type Counter = Arc<AtomicU64>;
type Gauge = Arc<AtomicU64>;
type Histogram = Arc<AtomicBucket<f64>>;
fn counter(&self, _: &K) -> Self::Counter {
Arc::new(AtomicU64::new(0))
}
fn gauge(&self, _: &K) -> Self::Gauge {
Arc::new(AtomicU64::new(0))
}
fn histogram(&self, _: &K) -> Self::Histogram {
Arc::new(AtomicBucket::new())
}
}