#[non_exhaustive]pub struct RuleEffect {
pub new_expression: Expression,
pub new_top: Vec<Expression>,
pub symbols: SymbolTable,
pub new_clauses: Vec<CnfClause>,
/* private fields */
}Expand description
Represents the result of applying a rule to an expression within a model.
A RuleEffect encapsulates the changes made to a model during a rule application.
It includes a new expression to replace the original one, an optional top-level constraint
to be added to the model, and any updates to the model’s symbol table.
This struct allows for representing side-effects of rule applications, ensuring that all modifications, including symbol table expansions and additional constraints, are accounted for and can be applied to the model consistently.
§Fields
new_expression: The updatedExpressionthat replaces the original one after applying the rule.new_top: An additional top-levelVec<Expression>constraint that should be added to the model. If no top-level constraint is needed, this field can be set to an empty vectorVec::new().symbols: ASymbolTablecontaining any new symbol definitions or modifications to be added to the model’s symbol table. If no symbols are modified, this field can be set to an empty symbol table.
§Usage
A RuleEffect can be created using one of the provided constructors:
RuleEffect::new: Creates an effect with a new expression, top-level constraint, and symbol modifications.RuleEffect::pure: Creates an effect with only a new expression and no side-effects on the symbol table or constraints.RuleEffect::with_symbols: Creates an effect with a new expression and symbol table modifications, but no top-level constraint.RuleEffect::with_top: Creates an effect with a new expression and a top-level constraint, but no symbol table modifications.RuleEffect::cnf: Creates an effect with a new expression, cnf clauses and symbol modifications, but no top-level constraints.
The apply method allows for applying the changes represented by the RuleEffect to a Model.
§Example
// Need to add an example§See Also
ApplicationResult: Represents the result of applying a rule, which may either be aRuleEffector anApplicationError.Model: The structure to which theRuleEffectchanges are applied.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.new_expression: Expression§new_top: Vec<Expression>§symbols: SymbolTable§new_clauses: Vec<CnfClause>Implementations§
Source§impl RuleEffect
impl RuleEffect
pub fn new( new_expression: Expression, new_top: Vec<Expression>, symbols: SymbolTable, ) -> RuleEffect
Sourcepub fn pure(new_expression: Expression) -> RuleEffect
pub fn pure(new_expression: Expression) -> RuleEffect
Represents an effect with no side effects on the model.
Sourcepub fn with_symbols(
new_expression: Expression,
symbols: SymbolTable,
) -> RuleEffect
pub fn with_symbols( new_expression: Expression, symbols: SymbolTable, ) -> RuleEffect
Represents an effect that also modifies the symbol table.
Sourcepub fn with_top(
new_expression: Expression,
new_top: Vec<Expression>,
) -> RuleEffect
pub fn with_top( new_expression: Expression, new_top: Vec<Expression>, ) -> RuleEffect
Represents an effect that also adds a top-level constraint to the model.
Sourcepub fn cnf(
new_expression: Expression,
new_clauses: Vec<CnfClause>,
symbols: SymbolTable,
) -> RuleEffect
pub fn cnf( new_expression: Expression, new_clauses: Vec<CnfClause>, symbols: SymbolTable, ) -> RuleEffect
Represents an effect that also adds clauses to the model.
Sourcepub fn deferred(
materialise: impl Fn(&SymbolTable) -> RuleEffect + Send + Sync + 'static,
) -> RuleEffect
pub fn deferred( materialise: impl Fn(&SymbolTable) -> RuleEffect + Send + Sync + 'static, ) -> RuleEffect
Defers constructing a concrete effect until the rewriter chooses to apply this rule.
This is intended for rule effects that allocate fresh names or otherwise depend on global
model state. Applicability checks can return a deferred effect without consuming those
effects; the rewriter calls RuleEffect::materialise only for the selected rule.
Sourcepub fn materialise(self, symbols: &SymbolTable) -> RuleEffect
pub fn materialise(self, symbols: &SymbolTable) -> RuleEffect
Returns the concrete effect for the current symbol table.
This consumes the selected effect: cloning a concrete effect can duplicate its expression, top-level constraints, clauses, and speculative symbol table. Before returning, the symbol snapshot is reduced to the bindings that the effect actually changes.
Sourcepub fn with_declaration_updates(
self,
updates: impl IntoIterator<Item = (DeclarationPtr, DeclarationKind)>,
) -> RuleEffect
pub fn with_declaration_updates( self, updates: impl IntoIterator<Item = (DeclarationPtr, DeclarationKind)>, ) -> RuleEffect
Adds declaration replacements that are committed only if this effect is selected.
Sourcepub fn updated_declaration_names(&self) -> impl Iterator<Item = Name>
pub fn updated_declaration_names(&self) -> impl Iterator<Item = Name>
Iterates over the names changed by deferred declaration updates.
Sourcepub fn added_symbols(&self, initial_symbols: &SymbolTable) -> BTreeSet<Name>
pub fn added_symbols(&self, initial_symbols: &SymbolTable) -> BTreeSet<Name>
Gets symbols added by this effect.
Walks this effect’s own symbols rather than diffing two whole tables. The rewriter asks this once per applied rule, and most effects are pure, so diffing made every rewrite cost a clone and a sort of the entire model symbol table.
Sourcepub fn changed_symbols(
&self,
initial_symbols: &SymbolTable,
) -> Vec<(Name, DeclarationPtr, DeclarationPtr)>
pub fn changed_symbols( &self, initial_symbols: &SymbolTable, ) -> Vec<(Name, DeclarationPtr, DeclarationPtr)>
Gets symbols changed by this effect.
Returns a list of tuples of (name, domain before effect, domain after effect), ordered by name.
Walks this effect’s symbols for the same reason as RuleEffect::added_symbols: a symbol
can only have changed if this effect carries its new value.
Trait Implementations§
Source§impl Clone for RuleEffect
impl Clone for RuleEffect
Source§fn clone(&self) -> RuleEffect
fn clone(&self) -> RuleEffect
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for RuleEffect
impl !RefUnwindSafe for RuleEffect
impl !UnwindSafe for RuleEffect
impl Send for RuleEffect
impl Sync for RuleEffect
impl Unpin for RuleEffect
impl UnsafeUnpin for RuleEffect
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 moreimpl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 352 bytes