hdrhistogram/core/
counter.rs
1use num_traits as num;
2use std::fmt;
3
4pub trait Counter:
9 num::Num
10 + num::ToPrimitive
11 + num::FromPrimitive
12 + num::Saturating
13 + num::CheckedSub
14 + num::CheckedAdd
15 + Copy
16 + PartialOrd<Self>
17 + fmt::Debug
18{
19 fn as_f64(&self) -> f64;
21 fn as_u64(&self) -> u64;
23}
24
25impl Counter for u8 {
26 #[inline]
27 fn as_f64(&self) -> f64 {
28 f64::from(*self)
29 }
30 #[inline]
31 fn as_u64(&self) -> u64 {
32 u64::from(*self)
33 }
34}
35
36impl Counter for u16 {
37 #[inline]
38 fn as_f64(&self) -> f64 {
39 f64::from(*self)
40 }
41 #[inline]
42 fn as_u64(&self) -> u64 {
43 u64::from(*self)
44 }
45}
46
47impl Counter for u32 {
48 #[inline]
49 fn as_f64(&self) -> f64 {
50 f64::from(*self)
51 }
52 #[inline]
53 fn as_u64(&self) -> u64 {
54 u64::from(*self)
55 }
56}
57
58impl Counter for u64 {
59 #[inline]
60 fn as_f64(&self) -> f64 {
61 *self as f64
62 }
63 #[inline]
64 fn as_u64(&self) -> u64 {
65 *self
66 }
67}