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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::sync::Arc;
use atomic_shim::AtomicU64;
use metrics::{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;
}
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())
}
}