BestFirstRule

Struct BestFirstRule 

Source
pub struct BestFirstRule { /* private fields */ }
Expand description

BestFirstRule represents a rule that executes the first child that evaluates to true. If no child evaluates to true, it tries siblings until one succeeds.

§Example

use dredd_rs::rule::*;

let mut rule = BestFirstRule::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 BestFirstRule

Source

pub fn new() -> Self

Create a new BestFirstRule

Source

pub fn set_eval_fn<F>(&mut self, f: F) -> &mut Self
where F: Fn(&RuleContext) -> RuleResult<bool> + 'static,

Set the evaluation function

Source

pub fn set_pre_execute_fn<F>(&mut self, f: F) -> &mut Self
where F: Fn(&mut RuleContext) -> RuleResult<()> + 'static,

Set the pre-execution function

Source

pub fn set_execute_fn<F>(&mut self, f: F) -> &mut Self
where F: Fn(&mut RuleContext) -> RuleResult<()> + 'static,

Set the execution function

Source

pub fn set_post_execute_fn<F>(&mut self, f: F) -> &mut Self
where F: Fn(&mut RuleContext) -> RuleResult<()> + 'static,

Set the post-execution function

Trait Implementations§

Source§

impl Default for BestFirstRule

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Rule for BestFirstRule

Source§

fn fire(&mut self, context: &mut RuleContext) -> RuleResult<bool>

Custom fire implementation for BestFirstRule that implements best-first execution

Source§

fn evaluate(&self, context: &RuleContext) -> RuleResult<bool>

Evaluate if this rule should execute
Source§

fn execute(&mut self, context: &mut RuleContext) -> RuleResult<()>

Execute the rule with proper error handling
Source§

fn children(&self) -> &[Box<dyn Rule>]

Get immutable reference to children
Source§

fn children_mut(&mut self) -> &mut Vec<Box<dyn Rule>>

Get mutable reference to children
Source§

fn add_child(&mut self, child: Box<dyn Rule>) -> RuleResult<()>

Add a child rule
Source§

fn add_children(&mut self, children: Vec<Box<dyn Rule>>) -> RuleResult<()>

Add multiple child rules

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.