#[cfg(test)]
#[path = "./instruction_test.rs"]
mod instruction_test;
pub trait InstructionOperations {
fn is_actionable(&self) -> bool;
}
#[derive(Debug, Clone, Default)]
pub struct PreProcessInstruction {
pub command: Option<String>,
pub arguments: Option<Vec<String>>,
}
impl PreProcessInstruction {
pub fn new() -> PreProcessInstruction {
Default::default()
}
}
impl InstructionOperations for PreProcessInstruction {
fn is_actionable(&self) -> bool {
return self.command.is_some();
}
}
#[derive(Debug, Clone, Default)]
pub struct ScriptInstruction {
pub label: Option<String>,
pub output: Option<String>,
pub command: Option<String>,
pub arguments: Option<Vec<String>>,
}
impl ScriptInstruction {
pub fn new() -> ScriptInstruction {
Default::default()
}
}
impl InstructionOperations for ScriptInstruction {
fn is_actionable(&self) -> bool {
return self.command.is_some();
}
}
#[derive(Debug, Clone)]
pub enum InstructionType {
Empty,
PreProcess(PreProcessInstruction),
Script(ScriptInstruction),
}
#[derive(Debug, Clone, Default)]
pub struct InstructionMetaInfo {
pub line: Option<usize>,
pub source: Option<String>,
}
impl InstructionMetaInfo {
pub fn new() -> InstructionMetaInfo {
Default::default()
}
}
#[derive(Debug, Clone)]
pub struct Instruction {
pub meta_info: InstructionMetaInfo,
pub instruction_type: InstructionType,
}
impl InstructionOperations for Instruction {
fn is_actionable(&self) -> bool {
match self.instruction_type {
InstructionType::Empty => false,
InstructionType::PreProcess(ref value) => value.is_actionable(),
InstructionType::Script(ref value) => value.is_actionable(),
}
}
}