use std::{marker::PhantomData, sync::Arc}; use git_features::{parallel, progress::Progress}; use super::Outcome; use crate::data::output; pub struct Statistics { total: Outcome, counts: Vec, progress: Arc>, _err: PhantomData, } impl Statistics where P: Progress, { pub fn new(progress: Arc>) -> Self { Statistics { total: Default::default(), counts: Default::default(), progress, _err: PhantomData::default(), } } } impl parallel::Reduce for Statistics where P: Progress, { type Input = Result<(Vec, Outcome), E>; type FeedProduce = (); type Output = (Vec, Outcome); type Error = E; fn feed(&mut self, item: Self::Input) -> Result { let (counts, stats) = item?; self.total.aggregate(stats); self.progress.lock().inc_by(counts.len()); self.counts.extend(counts); Ok(()) } fn finalize(self) -> Result { Ok((self.counts, self.total)) } }