rustible/src/modules/command/condition.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

2023-04-19 21:49:30 +02:00
use super::builder::{NoCondition, CreatesCondition, RemovesCondition, BothConditions};
2023-10-05 17:58:41 +02:00
#[derive(Clone, Debug, Serialize, Deserialize)]
2023-04-19 21:49:30 +02:00
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<CreatesCondition> for Option<SomeCondition> {
fn from(c: CreatesCondition) -> Option<SomeCondition> {
Some(SomeCondition::Creates(c))
}
}
impl From<RemovesCondition> for Option<SomeCondition> {
fn from(c: RemovesCondition) -> Option<SomeCondition> {
Some(SomeCondition::Removes(c))
}
}
impl From<BothConditions> for Option<SomeCondition> {
fn from(c: BothConditions) -> Option<SomeCondition> {
Some(SomeCondition::Both(c))
}
}
impl From<NoCondition> for Option<SomeCondition> {
fn from(_c: NoCondition) -> Option<SomeCondition> {
None
}
}