use crate::records::run::RunEntry;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ExecPhase {
Install,
Uninstall,
}
#[derive(Clone, Copy, Debug)]
pub struct ExecCommand<'a> {
pub phase: ExecPhase,
pub source: &'a RunEntry,
}
impl<'a> ExecCommand<'a> {
#[must_use]
pub fn filename(&self) -> &'a str {
&self.source.name
}
#[must_use]
pub fn parameters(&self) -> &'a str {
&self.source.parameters
}
#[must_use]
pub fn working_dir(&self) -> &'a str {
&self.source.working_dir
}
#[must_use]
pub fn description(&self) -> &'a str {
&self.source.description
}
}
#[derive(Clone)]
pub struct ExecIter<'a> {
install: std::slice::Iter<'a, RunEntry>,
uninstall: std::slice::Iter<'a, RunEntry>,
}
impl<'a> ExecIter<'a> {
pub(crate) fn new(install: &'a [RunEntry], uninstall: &'a [RunEntry]) -> Self {
Self {
install: install.iter(),
uninstall: uninstall.iter(),
}
}
}
impl<'a> Iterator for ExecIter<'a> {
type Item = ExecCommand<'a>;
fn next(&mut self) -> Option<Self::Item> {
if let Some(source) = self.install.next() {
return Some(ExecCommand {
phase: ExecPhase::Install,
source,
});
}
self.uninstall.next().map(|source| ExecCommand {
phase: ExecPhase::Uninstall,
source,
})
}
}