use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::sync::Arc;
pub trait RuleFlow {
fn version(&self) -> i32 {
1
}
fn flow<Obj: Serialize, Out: for<'a> Deserialize<'a>>(&self, obj: Obj) -> anyhow::Result<Out>;
}
#[async_trait::async_trait]
pub trait AsyncRuleFlow: RuleFlow + Sync + Send {
async fn async_flow<Obj: Serialize + Send, Out: for<'a> Deserialize<'a>>(
&self,
obj: Obj,
) -> anyhow::Result<Out> {
self.flow(obj)
}
}
pub trait CalcNode: Send + Sync {
fn when(&self, fs: Arc<dyn FunctionSet>, input: &Value) -> anyhow::Result<bool>;
}
pub trait Exec: Send + Sync {
fn execute(
&self,
fs: Arc<dyn FunctionSet>,
input: &Value,
output: &mut Value,
) -> anyhow::Result<()>;
}
pub trait Function: Send + Sync {
fn call(&self, fs: Arc<dyn FunctionSet>, args: Vec<Value>) -> anyhow::Result<Value>;
}
pub trait FunctionSet: Send + Sync {
fn get(&self, name: &str) -> Option<Arc<dyn Function>>;
}
#[async_trait::async_trait]
pub trait RuleEngineDiscovery<F> {
fn version(&self) -> i32 {
1
}
async fn upgrade(&self) -> F;
}