pub struct CountCollector(/* private fields */);Expand description
Opaque, shareable collector that accumulates a Count across the
worker threads of a crate::ConcurrentRunner walk.
Wraps the shared Arc<Mutex<Count>> behind a newtype so callers do
not handle the synchronization machinery directly. Clone is a
cheap reference-count bump, so each worker
can hold its own handle to the same tally while the config still
satisfies the 'static + Send + Sync bound of
crate::ConcurrentRunner. Recover the final tally with
CountCollector::into_count once every worker has joined.
Implementations§
Source§impl CountCollector
impl CountCollector
Sourcepub fn with_count(count: Count) -> Self
pub fn with_count(count: Count) -> Self
Creates a collector seeded with an existing tally.
Sourcepub fn add(&self, good: usize, total: usize)
pub fn add(&self, good: usize, total: usize)
Add a per-file (good, total) tally into the shared collector.
The aggregation is two monotonically-incremented counters, so a
peer worker that panicked mid-update leaves at worst a slightly
low tally — never an unsafe state. Recover the poisoned guard
(issue #445) and clear the poison so this and later callers — and
the collector’s final CountCollector::into_count — degrade
rather than cascade into a pool-wide abort the way .unwrap()
would.
Sourcepub fn into_count(self) -> Count
pub fn into_count(self) -> Count
Consumes the collector, returning the accumulated Count.
Call this only after every worker sharing a clone of this
collector has joined, so the underlying Arc reference count is
back to one. Degrades rather than panics in the unlikely event
that a worker panicked mid-update and poisoned the inner mutex
(issue #445): the recovered guard still holds the fully-applied
tally because the aggregation is two monotonically-incremented
counters.
If the Arc is unexpectedly still shared, a peer clone
survived past this call — a worker failed to join — which is a
caller-side coordination bug, not a recoverable runtime state.
Another clone may still call CountCollector::add afterwards,
so the value returned here is a best-effort snapshot of a tally
that is not yet final, not the complete aggregate the
#[must_use] return implies (issue #757). A debug_assert!
trips loudly on this path so the coordination bug surfaces in
debug and test builds; release builds still degrade to the
snapshot rather than panicking, honoring the project’s
no-panic-in-production contract.
Trait Implementations§
Source§impl Clone for CountCollector
impl Clone for CountCollector
Source§fn clone(&self) -> CountCollector
fn clone(&self) -> CountCollector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more