use crate::model::SnapshotId;
use crate::watch::cache::IncrementalCache;
#[derive(Debug, Clone, Default)]
pub struct ChangeSet {
pub files_added: usize,
pub files_removed: usize,
pub files_modified: usize,
pub files_unchanged: usize,
}
pub struct WatchState {
pub(crate) cache: IncrementalCache,
pub(crate) snapshot_counter: u32,
}
impl WatchState {
pub fn new() -> Self {
Self {
cache: IncrementalCache::new(),
snapshot_counter: 0,
}
}
pub(crate) fn next_snapshot_id(&mut self) -> SnapshotId {
self.snapshot_counter += 1;
SnapshotId::new(self.snapshot_counter)
.expect("watch snapshot counter exhausted (> u32::MAX)")
}
}
impl Default for WatchState {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn snapshot_id_allocation_is_monotonic() {
let mut state = WatchState::new();
let s1 = state.next_snapshot_id();
let s2 = state.next_snapshot_id();
assert_eq!(s1.to_raw(), 1);
assert_eq!(s2.to_raw(), 2);
}
}