pub struct ConditionalRule {
pub name: String,
pub transform: fn(&TLExpr) -> Option<TLExpr>,
pub guard: fn(&HashMap<String, TLExpr>) -> bool,
pub priority: RulePriority,
pub description: Option<String>,
/* private fields */
}Expand description
A conditional rewrite rule with guards and priority.
Conditional rules extend basic pattern matching with:
- Guard predicates that must be satisfied
- Priority ordering for conflict resolution
- Metadata for debugging and analysis
Fields§
§name: StringName for debugging and tracing
transform: fn(&TLExpr) -> Option<TLExpr>Transformation function
guard: fn(&HashMap<String, TLExpr>) -> boolGuard predicate (must return true for rule to apply)
priority: RulePriorityPriority level
description: Option<String>Optional description
Implementations§
Source§impl ConditionalRule
impl ConditionalRule
Sourcepub fn new(
name: impl Into<String>,
transform: fn(&TLExpr) -> Option<TLExpr>,
guard: fn(&HashMap<String, TLExpr>) -> bool,
) -> Self
pub fn new( name: impl Into<String>, transform: fn(&TLExpr) -> Option<TLExpr>, guard: fn(&HashMap<String, TLExpr>) -> bool, ) -> Self
Create a new conditional rule.
Sourcepub fn with_priority(self, priority: RulePriority) -> Self
pub fn with_priority(self, priority: RulePriority) -> Self
Set the priority of this rule.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Set the description of this rule.
Sourcepub fn apply(&mut self, expr: &TLExpr) -> Option<TLExpr>
pub fn apply(&mut self, expr: &TLExpr) -> Option<TLExpr>
Try to apply this rule to an expression.
Returns Some(transformed) if the rule applies, None otherwise.
Sourcepub fn application_count(&self) -> usize
pub fn application_count(&self) -> usize
Get the number of times this rule has been applied.
Sourcepub fn reset_counter(&mut self)
pub fn reset_counter(&mut self)
Reset the application counter.
Trait Implementations§
Source§impl Clone for ConditionalRule
impl Clone for ConditionalRule
Source§fn clone(&self) -> ConditionalRule
fn clone(&self) -> ConditionalRule
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ConditionalRule
impl RefUnwindSafe for ConditionalRule
impl Send for ConditionalRule
impl Sync for ConditionalRule
impl Unpin for ConditionalRule
impl UnwindSafe for ConditionalRule
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