1#![allow(clippy::integer_arithmetic)]
2pub mod counter;
3pub mod datapoint;
4mod metrics;
5pub use crate::metrics::{flush, query, set_host_id, set_panic_hook, submit};
6
7use std::sync::Arc;
8
9#[allow(clippy::redundant_allocation)]
11pub struct TokenCounter(Arc<&'static str>);
12
13impl TokenCounter {
14 pub fn new(name: &'static str) -> Self {
16 Self(Arc::new(name))
17 }
18
19 pub fn create_token(&self) -> CounterToken {
22 datapoint_info!(*self.0, ("count", Arc::strong_count(&self.0), i64));
26 CounterToken(self.0.clone())
27 }
28}
29
30#[allow(clippy::redundant_allocation)]
32pub struct CounterToken(Arc<&'static str>);
33
34impl Clone for CounterToken {
35 fn clone(&self) -> Self {
36 datapoint_info!(*self.0, ("count", Arc::strong_count(&self.0), i64));
40 CounterToken(self.0.clone())
41 }
42}
43
44impl Drop for CounterToken {
45 fn drop(&mut self) {
46 datapoint_info!(
50 *self.0,
51 ("count", Arc::strong_count(&self.0).saturating_sub(2), i64)
52 );
53 }
54}
55
56impl Drop for TokenCounter {
57 fn drop(&mut self) {
58 datapoint_info!(
59 *self.0,
60 ("count", Arc::strong_count(&self.0).saturating_sub(2), i64)
61 );
62 }
63}