pub struct RuleEngine { /* private fields */ }Expand description
规则引擎
Implementations§
Source§impl RuleEngine
impl RuleEngine
Sourcepub fn new(engine_config: ScriptEngineConfig) -> Result<Self>
pub fn new(engine_config: ScriptEngineConfig) -> Result<Self>
创建规则引擎
Sourcepub fn with_engine(engine: Arc<RhaiScriptEngine>) -> Self
pub fn with_engine(engine: Arc<RhaiScriptEngine>) -> Self
使用已有引擎创建
Sourcepub async fn register_rule(&self, rule: RuleDefinition) -> Result<()>
pub async fn register_rule(&self, rule: RuleDefinition) -> Result<()>
注册规则
Sourcepub async fn register_rules(&self, rules: Vec<RuleDefinition>) -> Result<()>
pub async fn register_rules(&self, rules: Vec<RuleDefinition>) -> Result<()>
批量注册规则
Sourcepub async fn register_group(&self, group: RuleGroupDefinition) -> Result<()>
pub async fn register_group(&self, group: RuleGroupDefinition) -> Result<()>
注册规则组
Sourcepub async fn evaluate_condition(
&self,
rule: &RuleDefinition,
context: &ScriptContext,
) -> Result<bool>
pub async fn evaluate_condition( &self, rule: &RuleDefinition, context: &ScriptContext, ) -> Result<bool>
评估规则条件
Sourcepub fn execute_action<'a>(
&'a self,
action: &'a RuleAction,
context: &'a mut ScriptContext,
) -> Pin<Box<dyn Future<Output = Result<RuleExecutionResult>> + Send + 'a>>
pub fn execute_action<'a>( &'a self, action: &'a RuleAction, context: &'a mut ScriptContext, ) -> Pin<Box<dyn Future<Output = Result<RuleExecutionResult>> + Send + 'a>>
执行规则动作
Sourcepub async fn execute_rule(
&self,
rule_id: &str,
context: &mut ScriptContext,
) -> Result<Option<RuleExecutionResult>>
pub async fn execute_rule( &self, rule_id: &str, context: &mut ScriptContext, ) -> Result<Option<RuleExecutionResult>>
执行单个规则
Sourcepub async fn execute_group(
&self,
group_id: &str,
context: &mut ScriptContext,
) -> Result<RuleGroupExecutionResult>
pub async fn execute_group( &self, group_id: &str, context: &mut ScriptContext, ) -> Result<RuleGroupExecutionResult>
执行规则组
Sourcepub async fn execute_all(
&self,
context: &mut ScriptContext,
) -> Result<Vec<RuleExecutionResult>>
pub async fn execute_all( &self, context: &mut ScriptContext, ) -> Result<Vec<RuleExecutionResult>>
执行所有匹配的规则
Sourcepub async fn get_rule(&self, rule_id: &str) -> Option<RuleDefinition>
pub async fn get_rule(&self, rule_id: &str) -> Option<RuleDefinition>
获取规则
Sourcepub async fn list_rules(&self) -> Vec<RuleDefinition>
pub async fn list_rules(&self) -> Vec<RuleDefinition>
列出所有规则
Sourcepub async fn list_rules_by_tag(&self, tag: &str) -> Vec<RuleDefinition>
pub async fn list_rules_by_tag(&self, tag: &str) -> Vec<RuleDefinition>
按标签过滤规则
Sourcepub async fn unregister_rule(&self, rule_id: &str) -> bool
pub async fn unregister_rule(&self, rule_id: &str) -> bool
移除规则
Sourcepub async fn enable_rule(&self, rule_id: &str) -> Result<()>
pub async fn enable_rule(&self, rule_id: &str) -> Result<()>
启用规则
Sourcepub async fn disable_rule(&self, rule_id: &str) -> Result<()>
pub async fn disable_rule(&self, rule_id: &str) -> Result<()>
禁用规则
Sourcepub async fn rule_count(&self) -> usize
pub async fn rule_count(&self) -> usize
规则数量
Auto Trait Implementations§
impl Freeze for RuleEngine
impl !RefUnwindSafe for RuleEngine
impl Send for RuleEngine
impl Sync for RuleEngine
impl Unpin for RuleEngine
impl UnsafeUnpin for RuleEngine
impl !UnwindSafe for RuleEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more