50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
|
use super::builder::{NoCondition, CreatesCondition, RemovesCondition, BothConditions};
|
||
|
|
||
|
#[derive(Clone, Debug, Serialize)]
|
||
|
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
|
||
|
}
|
||
|
}
|