userd 0.2.0

A user daemon, managing services and regular running of jobs, in user space.
use futures::future::BoxFuture;

use crate::{conditions, prelude::*};

pub(crate) mod file;

pub(crate) trait Condition {
    fn check(&self) -> BoxFuture<'static, Result<bool>>;
    fn wait_for_change(&self) -> BoxFuture<'static, Result<()>>;
}

pub(crate) type ConditionBox = Box<dyn Condition + Send + Sync>;

fn build_condition(condition: config::Condition) -> Result<ConditionBox> {
    match condition {
        config::Condition::File {
            filename,
            negate,
            check,
            update_check,
        } => Ok(Box::new(conditions::file::File::new(
            filename,
            negate,
            check,
            update_check,
        ))),
    }
}

pub(crate) fn build_conditions(conditions: Vec<config::Condition>) -> Result<Vec<ConditionBox>> {
    conditions
        .into_iter()
        .map(|condition| build_condition(condition))
        .collect()
}