pub trait Summary {
fn sample_sum(&self) -> f64;
fn sample_count(&self) -> u64;
fn quantile(&self, _: f64) -> Option<f64>;
}
pub trait SummaryProvider {
type Opts: Clone + Send + Sync;
type Summary: Summary;
fn new_provider(opts: &Self::Opts) -> Self;
fn observe(&self, _: f64);
fn snapshot(&self) -> Self::Summary;
}
pub trait NonConcurrentSummaryProvider {
type Opts: Clone + Send + Sync;
type Summary: Summary;
fn new_provider(opts: &Self::Opts) -> Self;
fn observe(&mut self, _: f64);
fn snapshot(&self) -> Self::Summary;
}
impl<T: SummaryProvider> NonConcurrentSummaryProvider for T {
type Opts = T::Opts;
type Summary = T::Summary;
fn new_provider(opts: &Self::Opts) -> Self {
<Self as SummaryProvider>::new_provider(opts)
}
fn observe(&mut self, val: f64) {
SummaryProvider::observe(self, val)
}
fn snapshot(&self) -> Self::Summary {
SummaryProvider::snapshot(self)
}
}
pub trait SummaryMetric: NonConcurrentSummaryProvider + Send + Sync + Clone {}
impl<T: NonConcurrentSummaryProvider + Send + Sync + Clone> SummaryMetric for T {}