use crate::Result;
use crate::schemes::template::prelude::{change::Change, r#move::Move, variable::Variable};
use std::collections::HashMap;
use std::path::Path;
pub trait ToTask {
fn to_task(self, path: &Path) -> Task;
}
#[derive(PartialEq, Eq, Debug)]
pub enum Task {
Variable(Variable),
Change(Change),
Move(Move),
}
impl Task {
pub fn execute(&self, global: &mut HashMap<String, String>) -> Result<()> {
match self {
Self::Variable(v) => v.execute(global),
Self::Change(c) => c.execute(global),
Self::Move(m) => m.execute(global),
}
}
fn index(&self) -> u8 {
match *self {
Self::Variable(_) => 1,
Self::Change(_) => 2,
Self::Move(_) => 3,
}
}
}
impl Ord for Task {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.index().cmp(&other.index())
}
}
impl PartialOrd for Task {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}