use crate::KeyValue;
use core::fmt;
use std::sync::Arc;
use super::SyncInstrument;
#[derive(Clone)]
#[non_exhaustive]
pub struct Counter<T>(Arc<dyn SyncInstrument<T> + Send + Sync>);
impl<T> fmt::Debug for Counter<T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_fmt(format_args!("Counter<{}>", std::any::type_name::<T>()))
}
}
impl<T> Counter<T> {
pub fn new(inner: Arc<dyn SyncInstrument<T> + Send + Sync>) -> Self {
Counter(inner)
}
pub fn add(&self, value: T, attributes: &[KeyValue]) {
self.0.measure(value, attributes)
}
}
#[derive(Clone)]
#[non_exhaustive]
pub struct ObservableCounter<T> {
_marker: std::marker::PhantomData<T>,
}
impl<T> ObservableCounter<T> {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
ObservableCounter {
_marker: std::marker::PhantomData,
}
}
}
impl<T> fmt::Debug for ObservableCounter<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_fmt(format_args!(
"ObservableCounter<{}>",
std::any::type_name::<T>()
))
}
}