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