pub struct RuleConflictResolver { /* private fields */ }Expand description
Production-quality conflict detector and resolver for logic rule sets.
See the module-level documentation for a full description.
Implementations§
Source§impl RuleConflictResolver
impl RuleConflictResolver
Sourcepub fn new(config: ResolverConfig) -> Self
pub fn new(config: ResolverConfig) -> Self
Create a new resolver with the given configuration.
Sourcepub fn add_rule(&mut self, rule: LogicRule) -> Result<(), ResolverError>
pub fn add_rule(&mut self, rule: LogicRule) -> Result<(), ResolverError>
Add a rule to the resolver.
An immediate check for ConflictType::DirectContradiction with every
existing rule that shares the same head is performed. The statistics are
updated but the conflicts are not automatically resolved.
§Errors
ResolverError::MaxRulesExceededwhen the hard cap would be breached.
Sourcepub fn remove_rule(&mut self, id: &str) -> Result<(), ResolverError>
pub fn remove_rule(&mut self, id: &str) -> Result<(), ResolverError>
Sourcepub fn detect_conflicts(&mut self) -> Vec<ConflictRecord>
pub fn detect_conflicts(&mut self) -> Vec<ConflictRecord>
Run a full conflict scan and return all detected ConflictRecords.
Detection order:
Sourcepub fn resolve(
&mut self,
conflict: &ConflictRecord,
) -> Result<String, ResolverError>
pub fn resolve( &mut self, conflict: &ConflictRecord, ) -> Result<String, ResolverError>
Resolve a single conflict record and return the winning rule ID.
The resolution strategy is taken from self.config.default_strategy.
§Errors
ResolverError::RuleNotFoundwhen a rule referenced in the conflict no longer exists.ResolverError::UnresolvableConflictwhen the strategy isResolutionStrategy::AskOracle.ResolverError::CyclicDependencyfor cyclic conflicts (cannot be resolved automatically).
Sourcepub fn resolve_all(
&mut self,
) -> Vec<(ConflictRecord, Result<String, ResolverError>)>
pub fn resolve_all( &mut self, ) -> Vec<(ConflictRecord, Result<String, ResolverError>)>
Resolve all conflicts returned by detect_conflicts and return each
result paired with its conflict record.
Sourcepub fn applicable_rules<'a>(&'a self, facts: &[String]) -> Vec<&'a LogicRule>
pub fn applicable_rules<'a>(&'a self, facts: &[String]) -> Vec<&'a LogicRule>
Return all rules whose positive body conditions are a subset of facts.
Negated body conditions (prefixed with "NOT:") are intentionally
ignored during this applicability check.
Sourcepub fn winning_rule<'a>(
&'a self,
head: &str,
facts: &[String],
) -> Option<&'a LogicRule>
pub fn winning_rule<'a>( &'a self, head: &str, facts: &[String], ) -> Option<&'a LogicRule>
Among the applicable rules for head, pick the winner according to the
configured default strategy.
Returns None when no rule for that head is applicable.
Sourcepub fn stats(&self) -> ResolverStats
pub fn stats(&self) -> ResolverStats
Return a snapshot of current resolver statistics.
Auto Trait Implementations§
impl Freeze for RuleConflictResolver
impl RefUnwindSafe for RuleConflictResolver
impl Send for RuleConflictResolver
impl Sync for RuleConflictResolver
impl Unpin for RuleConflictResolver
impl UnsafeUnpin for RuleConflictResolver
impl UnwindSafe for RuleConflictResolver
Blanket Implementations§
impl<T> Allocation for T
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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