pub struct RuleEngine { /* private fields */ }Expand description
规则引擎
Implementations§
Source§impl RuleEngine
impl RuleEngine
Sourcepub fn new(engine_config: ScriptEngineConfig) -> Result<RuleEngine, Error>
pub fn new(engine_config: ScriptEngineConfig) -> Result<RuleEngine, Error>
创建规则引擎
Sourcepub fn with_engine(engine: Arc<RhaiScriptEngine>) -> RuleEngine
pub fn with_engine(engine: Arc<RhaiScriptEngine>) -> RuleEngine
使用已有引擎创建
Sourcepub async fn register_rule(&self, rule: RuleDefinition) -> Result<(), Error>
pub async fn register_rule(&self, rule: RuleDefinition) -> Result<(), Error>
注册规则
Sourcepub async fn register_rules(
&self,
rules: Vec<RuleDefinition>,
) -> Result<(), Error>
pub async fn register_rules( &self, rules: Vec<RuleDefinition>, ) -> Result<(), Error>
批量注册规则
Sourcepub async fn register_group(
&self,
group: RuleGroupDefinition,
) -> Result<(), Error>
pub async fn register_group( &self, group: RuleGroupDefinition, ) -> Result<(), Error>
注册规则组
Sourcepub async fn load_rules_from_yaml(
&self,
path: &str,
) -> Result<Vec<String>, Error>
pub async fn load_rules_from_yaml( &self, path: &str, ) -> Result<Vec<String>, Error>
从 YAML 加载规则
Sourcepub async fn load_rules_from_json(
&self,
path: &str,
) -> Result<Vec<String>, Error>
pub async fn load_rules_from_json( &self, path: &str, ) -> Result<Vec<String>, Error>
从 JSON 加载规则
Sourcepub async fn evaluate_condition(
&self,
rule: &RuleDefinition,
context: &ScriptContext,
) -> Result<bool, Error>
pub async fn evaluate_condition( &self, rule: &RuleDefinition, context: &ScriptContext, ) -> Result<bool, Error>
评估规则条件
Sourcepub fn execute_action<'a>(
&'a self,
action: &'a RuleAction,
context: &'a mut ScriptContext,
) -> Pin<Box<dyn Future<Output = Result<RuleExecutionResult, Error>> + Send + 'a>>
pub fn execute_action<'a>( &'a self, action: &'a RuleAction, context: &'a mut ScriptContext, ) -> Pin<Box<dyn Future<Output = Result<RuleExecutionResult, Error>> + Send + 'a>>
执行规则动作
Sourcepub async fn execute_rule(
&self,
rule_id: &str,
context: &mut ScriptContext,
) -> Result<Option<RuleExecutionResult>, Error>
pub async fn execute_rule( &self, rule_id: &str, context: &mut ScriptContext, ) -> Result<Option<RuleExecutionResult>, Error>
执行单个规则
Sourcepub async fn execute_group(
&self,
group_id: &str,
context: &mut ScriptContext,
) -> Result<RuleGroupExecutionResult, Error>
pub async fn execute_group( &self, group_id: &str, context: &mut ScriptContext, ) -> Result<RuleGroupExecutionResult, Error>
执行规则组
Sourcepub async fn execute_all(
&self,
context: &mut ScriptContext,
) -> Result<Vec<RuleExecutionResult>, Error>
pub async fn execute_all( &self, context: &mut ScriptContext, ) -> Result<Vec<RuleExecutionResult>, Error>
执行所有匹配的规则
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 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage