1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::sync::Arc;
4
5pub trait RuleFlow {
7 fn version(&self) -> i32 {
8 1
9 }
10 fn flow<Obj: Serialize, Out: for<'a> Deserialize<'a>>(&self, obj: Obj) -> anyhow::Result<Out>;
11}
12
13#[async_trait::async_trait]
14pub trait AsyncRuleFlow: RuleFlow + Sync + Send {
15 async fn async_flow<Obj: Serialize + Send, Out: for<'a> Deserialize<'a>>(
16 &self,
17 obj: Obj,
18 ) -> anyhow::Result<Out> {
19 self.flow(obj)
20 }
21}
22
23pub trait CalcNode: Send + Sync {
25 fn when(&self, fs: Arc<dyn FunctionSet>, input: &Value) -> anyhow::Result<bool>;
26}
27pub trait Exec: Send + Sync {
29 fn execute(
30 &self,
31 fs: Arc<dyn FunctionSet>,
32 input: &Value,
33 output: &mut Value,
34 ) -> anyhow::Result<()>;
35}
36pub trait Function: Send + Sync {
38 fn call(&self, fs: Arc<dyn FunctionSet>, args: Vec<Value>) -> anyhow::Result<Value>;
39}
40pub trait FunctionSet: Send + Sync {
42 fn get(&self, name: &str) -> Option<Arc<dyn Function>>;
43}
44
45#[async_trait::async_trait]
46pub trait RuleEngineDiscovery<F> {
47 fn version(&self) -> i32 {
48 1
49 }
50 async fn upgrade(&self) -> F;
51}