Skip to main content

pacenotes_installer\restore/
changes.rs

1/// What the run that followed a point did, counted for the list of points.
2///
3/// Derived, because nothing records what a run was about and a date alone does
4/// not help a user choose.
5#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
6pub struct Changes {
7    pub added: usize,
8    pub removed: usize,
9    pub updated: usize,
10}
11
12impl Changes {
13    pub fn is_empty(&self) -> bool {
14        self.added == 0 && self.removed == 0 && self.updated == 0
15    }
16}
17
18/// `after` is the next point's snapshot, or the live ledger for the newest point.
19pub fn changes(before: &super::Snapshot, after: &super::Snapshot) -> Changes {
20    let mut counted = Changes::default();
21    for (key, then) in before {
22        match after.get(key) {
23            None => counted.removed += 1,
24            Some(now) if now.sha256 != then.sha256 => counted.updated += 1,
25            Some(_) => {}
26        }
27    }
28    counted.added = after
29        .keys()
30        .filter(|key| !before.contains_key(*key))
31        .count();
32    counted
33}