Skip to main content

CountCollector

Struct CountCollector 

Source
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

Source

pub fn new() -> Self

Creates an empty collector.

Source

pub fn with_count(count: Count) -> Self

Creates a collector seeded with an existing tally.

Source

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.

Source

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

Source§

fn clone(&self) -> CountCollector

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CountCollector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CountCollector

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.