use qubit_function::Consumer;
use crate::{
model::ProgressEvent,
reporter::{
ProgressReporter,
format::MetricSnapshotFormatter,
},
};
pub struct FormattedProgressReporter<F, C> {
formatter: F,
consumer: C,
}
impl<F, C> FormattedProgressReporter<F, C> {
#[inline]
pub const fn new(formatter: F, consumer: C) -> Self {
Self { formatter, consumer }
}
#[inline]
pub const fn formatter(&self) -> &F {
&self.formatter
}
#[inline]
pub const fn consumer(&self) -> &C {
&self.consumer
}
}
impl<F, C> ProgressReporter for FormattedProgressReporter<F, C>
where
F: MetricSnapshotFormatter,
C: Consumer<String> + Send + Sync,
{
fn report(&self, event: &ProgressEvent) {
for snapshot in event.metric_snapshots() {
let line = self.formatter.format(&snapshot);
self.consumer.accept(&line);
}
}
}