use super::builder::{NoCondition, CreatesCondition, RemovesCondition, BothConditions}; #[derive(Clone, Debug, Serialize, Deserialize)] pub enum SomeCondition { #[serde(rename="creates")] Creates(CreatesCondition), #[serde(rename="removes")] Removes(RemovesCondition), #[serde(rename="creates_and_removes")] Both(BothConditions), } impl SomeCondition { pub fn should_run(&self) -> bool { match self { Self::Creates(c) => { ! c.0.exists() }, Self::Removes(c) => { c.0.exists() }, Self::Both(c) => { ! c.0.0.exists() || c.1.0.exists() } } } } impl From for Option { fn from(c: CreatesCondition) -> Option { Some(SomeCondition::Creates(c)) } } impl From for Option { fn from(c: RemovesCondition) -> Option { Some(SomeCondition::Removes(c)) } } impl From for Option { fn from(c: BothConditions) -> Option { Some(SomeCondition::Both(c)) } } impl From for Option { fn from(_c: NoCondition) -> Option { None } }