pub struct RuleEngine { /* private fields */ }Expand description
Rule engine for evaluating rule-based constraints against live Quins.
Internally owns a SlgArena (the 42MB Webizen VM) into which parsed N3 rules
are registered and fired. The evaluate method matches an input Quin against
the conclusions asserted by fired rules, returning real pass/fail verdicts.
Implementations§
Source§impl RuleEngine
impl RuleEngine
Sourcepub fn with_contract(contract_hash: u64) -> Self
pub fn with_contract(contract_hash: u64) -> Self
Create a new rule engine bound to a specific contract graph hash.
The contract hash is used when compiling N3 rules to deontic norms —
it becomes the context field of the compiled norm Quin.
Sourcepub fn add_ruleset(&mut self, ruleset: RuleSet)
pub fn add_ruleset(&mut self, ruleset: RuleSet)
Add a pre-built ruleset to the engine and fire its rules in the VM.
Sourcepub fn load_n3(&mut self, name: &str, n3_source: &str) -> usize
pub fn load_n3(&mut self, name: &str, n3_source: &str) -> usize
Load an N3 source string as a new ruleset, parse it, register and fire the rules in the internal VM arena.
Returns the number of rules parsed and fired.
Sourcepub fn get_ruleset(&self, name: &str) -> Option<&RuleSet>
pub fn get_ruleset(&self, name: &str) -> Option<&RuleSet>
Get a ruleset by name.
Sourcepub fn evaluate(&self, quin: &NQuin) -> Vec<RuleResult>
pub fn evaluate(&self, quin: &NQuin) -> Vec<RuleResult>
Evaluate all rulesets against a Quin by checking whether the Quin matches the premise pattern of any fired rule (norm) in the arena.
After fire_registered_rules, the arena contains deontic norms derived
from rule premises. Each norm’s predicate encodes the property path
(shifted left 8 bits) and a deontic opcode in the low byte. This method
extracts the property path and checks whether the input Quin’s
(subject, predicate, object) matches any norm’s premise pattern.
Each evaluation emits a q42:ruleEvaluation WAL audit event.
Returns one RuleResult per rule across all rulesets.
Sourcepub fn evaluate_silent(&self, quin: &NQuin) -> Vec<RuleResult>
pub fn evaluate_silent(&self, quin: &NQuin) -> Vec<RuleResult>
Evaluate without WAL logging (for hot paths or testing).
Collects active norms from the arena, extracts each norm’s premise pattern (subject, property_path, object), and checks whether the input Quin matches. A rule “passes” when its norm’s premise pattern matches the input Quin — meaning the rule fires for this input.
Sourcepub fn ruleset_count(&self) -> usize
pub fn ruleset_count(&self) -> usize
Number of rulesets loaded.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Total number of rules across all rulesets.
Sourcepub fn arena_rule_count(&self) -> usize
pub fn arena_rule_count(&self) -> usize
Number of rules currently registered in the VM arena.
Trait Implementations§
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§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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 more