#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Action {
Create,
Update,
Restore,
Unchanged,
Delete,
Forget,
}
impl Action {
#[must_use]
pub const fn writes(self) -> bool {
matches!(self, Self::Create | Self::Update | Self::Restore)
}
#[must_use]
pub const fn touches_disk(self) -> bool {
self.writes() || matches!(self, Self::Delete)
}
}
#[cfg(test)]
mod tests {
use super::*;
const ALL: [Action; 6] = [
Action::Create,
Action::Update,
Action::Restore,
Action::Unchanged,
Action::Delete,
Action::Forget,
];
#[test]
fn action_writes_only_for_create_update_restore() {
let writing: Vec<Action> = ALL.into_iter().filter(|a| a.writes()).collect();
assert_eq!(writing, [Action::Create, Action::Update, Action::Restore]);
}
#[test]
fn action_touches_disk_except_unchanged_and_forget() {
let idle: Vec<Action> = ALL.into_iter().filter(|a| !a.touches_disk()).collect();
assert_eq!(idle, [Action::Unchanged, Action::Forget]);
}
}