pub struct RuleSetBuilder { /* private fields */ }Expand description
Builder for constructing a RuleSet.
Rules are defined via closures and compiled into an immutable, thread-safe execution structure.
§Example
use ooroo::{RuleSetBuilder, field, rule_ref};
let ruleset = RuleSetBuilder::new()
.rule("age_ok", |r| r.when(field("age").gte(18_i64)))
.rule("active", |r| r.when(field("status").eq("active")))
.rule("allowed", |r| r.when(rule_ref("age_ok").and(rule_ref("active"))))
.terminal("allowed", 0)
.compile()
.unwrap();Implementations§
Source§impl RuleSetBuilder
impl RuleSetBuilder
Sourcepub fn rule(
self,
name: &str,
f: impl FnOnce(RuleBuilder) -> RuleBuilder,
) -> Self
pub fn rule( self, name: &str, f: impl FnOnce(RuleBuilder) -> RuleBuilder, ) -> Self
Define a rule. The closure must call .when(expr) to set the condition.
If .when() is not called, compilation will fail with
CompileError::MissingCondition.
Sourcepub fn terminal(self, rule_name: &str, priority: u32) -> Self
pub fn terminal(self, rule_name: &str, priority: u32) -> Self
Register a rule as a terminal with the given priority. Lower priority numbers are evaluated first.
Sourcepub fn compile(self) -> Result<RuleSet, CompileError>
pub fn compile(self) -> Result<RuleSet, CompileError>
Trait Implementations§
Source§impl Debug for RuleSetBuilder
impl Debug for RuleSetBuilder
Source§impl Default for RuleSetBuilder
impl Default for RuleSetBuilder
Source§fn default() -> RuleSetBuilder
fn default() -> RuleSetBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RuleSetBuilder
impl RefUnwindSafe for RuleSetBuilder
impl Send for RuleSetBuilder
impl Sync for RuleSetBuilder
impl Unpin for RuleSetBuilder
impl UnsafeUnpin for RuleSetBuilder
impl UnwindSafe for RuleSetBuilder
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