1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::collections::HashMap;

use crate::context::PicoContext;
use crate::errors::PicoError;
//use crate::state::PicoState;
use crate::rules::PicoRules;
use crate::runtime::PicoRuntime;
//use crate::values::PicoValue;
use anyhow::Result as AnyHowResult;
use serde_json::Value as PicoValue;

#[derive(Clone, Debug)]
pub enum ActionValue {
    Continue,
    Setting(HashMap<String, PicoValue>),
    Stop(Option<String>),
    BreakTo(uuid::Uuid),
}

pub type MyResult<T> = AnyHowResult<T, PicoError>;
pub type ConditionResult = MyResult<bool>;
pub type ValueResult = MyResult<PicoValue>;
pub type ActionResult = MyResult<ActionValue>;

// pub type FnResult = Result<ExecutionResult, PicoError>;

pub trait ConditionExecution {
    fn run_with_context(
        &self,
        pico_rule: &PicoRules,
        runtime: &mut PicoRuntime,
        ctx: &mut PicoContext,
    ) -> MyResult<bool> {
        Err(PicoError::Crash("Not implemented".to_string()))
    }
}

pub trait ValueExecution {
    /// Evaluates a value within the context of a `PicoRule`, variables namespaces and the current context
    ///
    /// # Arguments
    ///
    /// * `pico_rule` - The rule file thats being used
    /// * `runtime` - PicoRuntime
    /// * `ctx` - the context, hold the initial JSON and any local variables
    fn run_with_context(
        &self,
        pico_rule: &PicoRules,
        runtime: &mut PicoRuntime,
        ctx: &mut PicoContext,
    ) -> MyResult<PicoValue> {
        Err(PicoError::Crash("Not implemented".to_string()))
    }
}

pub trait ActionExecution {
    fn run_with_context(
        &self,
        pico_rule: &PicoRules,
        runtime: &mut PicoRuntime,
        ctx: &mut PicoContext,
    ) -> MyResult<ActionValue> {
        Err(PicoError::Crash("Not implemented".to_string()))
    }
}

#[test]
fn has_name() {
    assert_eq!(2 + 2, 4);
}