use crate::file::build::Facts;
pub(super) struct ProgramWalkGuard<'f, 'a> {
facts: &'f mut Facts<'a>,
row: usize,
}
impl<'f, 'a> ProgramWalkGuard<'f, 'a> {
pub(super) fn new(facts: &'f mut Facts<'a>) -> Option<Self> {
let row = facts.units.len().checked_sub(1)?;
facts.units.get(row)?;
Some(Self { facts, row })
}
pub(super) fn facts(&mut self) -> &mut Facts<'a> {
self.facts
}
pub(super) fn complete(self) {
if let Some(unit) = self.facts.units.get_mut(self.row) {
unit.complete_walk();
}
}
}
impl Drop for ProgramWalkGuard<'_, '_> {
fn drop(&mut self) {
if let Some(unit) = self.facts.units.get_mut(self.row) {
unit.interrupt_walk();
}
}
}