Skip to main content

tuwunel_service/migrations/
tally.rs

1/// What a repair made of one finding.
2///
3/// A repair reads its row again before writing, so a finding can turn out stale by
4/// the time it is acted on.
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub(super) enum Outcome {
7	/// The row was rewritten.
8	Repaired,
9
10	/// The row was deleted.
11	Removed,
12
13	/// The row was left alone by design, such as one the check cannot read.
14	Skipped,
15
16	/// The row was no longer defective, or gone, when read again.
17	Stale,
18}
19
20/// How many findings of a pass came to each outcome.
21///
22/// Each finding's repair returns its own outcome, so repairs can run concurrently
23/// and the totals still add up.
24#[derive(Default)]
25pub(super) struct Tally {
26	/// Findings whose row was rewritten.
27	pub(super) repaired: usize,
28
29	/// Findings whose row was deleted.
30	pub(super) removed: usize,
31
32	/// Findings left alone by design.
33	pub(super) skipped: usize,
34
35	/// Findings stale by the time they were acted on.
36	pub(super) stale: usize,
37}
38
39impl Tally {
40	pub(super) fn record(mut self, outcome: Outcome) -> Self {
41		let count = match outcome {
42			| Outcome::Repaired => &mut self.repaired,
43			| Outcome::Removed => &mut self.removed,
44			| Outcome::Skipped => &mut self.skipped,
45			| Outcome::Stale => &mut self.stale,
46		};
47
48		*count = count.saturating_add(1);
49		self
50	}
51}