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