pub struct ChainRule { /* private fields */ }Expand description
ChainRule represents a rule that can have at most one child. When executed, it will run its child rule if the evaluation succeeds.
§Example
use dredd_rs::rule::*;
let mut rule = ChainRule::new();
rule.set_eval_fn(|context| {
context.get_bool("should_execute")
});
rule.set_execute_fn(|context| {
context.set_bool("executed", true);
Ok(())
});
let mut context = RuleContext::new();
context.set_bool("should_execute", true);
let result = rule.fire(&mut context).unwrap();
assert!(result);Implementations§
Source§impl ChainRule
impl ChainRule
Sourcepub fn set_eval_fn<F>(&mut self, f: F) -> &mut Self
pub fn set_eval_fn<F>(&mut self, f: F) -> &mut Self
Set the evaluation function
Sourcepub fn set_pre_execute_fn<F>(&mut self, f: F) -> &mut Self
pub fn set_pre_execute_fn<F>(&mut self, f: F) -> &mut Self
Set the pre-execution function
Sourcepub fn set_execute_fn<F>(&mut self, f: F) -> &mut Self
pub fn set_execute_fn<F>(&mut self, f: F) -> &mut Self
Set the execution function
Sourcepub fn set_post_execute_fn<F>(&mut self, f: F) -> &mut Self
pub fn set_post_execute_fn<F>(&mut self, f: F) -> &mut Self
Set the post-execution function
Sourcepub fn set_child(&mut self, child: Box<dyn Rule>) -> RuleResult<&mut Self>
pub fn set_child(&mut self, child: Box<dyn Rule>) -> RuleResult<&mut Self>
Add a child rule (ChainRule can only have one child)
Trait Implementations§
Source§impl Rule for ChainRule
impl Rule for ChainRule
Source§fn fire(&mut self, context: &mut RuleContext) -> RuleResult<bool>
fn fire(&mut self, context: &mut RuleContext) -> RuleResult<bool>
Custom fire implementation for ChainRule that handles single child execution
Source§fn evaluate(&self, context: &RuleContext) -> RuleResult<bool>
fn evaluate(&self, context: &RuleContext) -> RuleResult<bool>
Evaluate if this rule should execute
Source§fn execute(&mut self, context: &mut RuleContext) -> RuleResult<()>
fn execute(&mut self, context: &mut RuleContext) -> RuleResult<()>
Execute the rule with proper error handling
Source§fn add_children(&mut self, children: Vec<Box<dyn Rule>>) -> RuleResult<()>
fn add_children(&mut self, children: Vec<Box<dyn Rule>>) -> RuleResult<()>
Add multiple child rules
Auto Trait Implementations§
impl Freeze for ChainRule
impl !RefUnwindSafe for ChainRule
impl !Send for ChainRule
impl !Sync for ChainRule
impl Unpin for ChainRule
impl !UnwindSafe for ChainRule
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