#[non_exhaustive]pub struct Reduction {
pub new_expression: Expression,
pub new_top: Expression,
pub symbols: HashMap<Name, DecisionVariable>,
}
Expand description
Represents the result of applying a rule to an expression within a model.
A Reduction
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 updatedExpression
that replaces the original one after applying the rule.new_top
: An additional top-levelExpression
constraint that should be added to the model. If no top-level constraint is needed, this field can be set toExpression::Nothing
.symbols
: ASymbolTable
containing 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 Reduction
can be created using one of the provided constructors:
Reduction::new
: Creates a reduction with a new expression, top-level constraint, and symbol modifications.Reduction::pure
: Creates a reduction with only a new expression and no side-effects on the symbol table or constraints.Reduction::with_symbols
: Creates a reduction with a new expression and symbol table modifications, but no top-level constraint.Reduction::with_top
: Creates a reduction with a new expression and a top-level constraint, but no symbol table modifications.
The apply
method allows for applying the changes represented by the Reduction
to a Model
.
§Example
// Need to add an example
§See Also
ApplicationResult
: Represents the result of applying a rule, which may either be aReduction
or anApplicationError
.Model
: The structure to which theReduction
changes 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: Expression
§symbols: HashMap<Name, DecisionVariable>
Implementations§
Source§impl Reduction
impl Reduction
pub fn new( new_expression: Expression, new_top: Expression, symbols: HashMap<Name, DecisionVariable>, ) -> Reduction
Sourcepub fn pure(new_expression: Expression) -> Reduction
pub fn pure(new_expression: Expression) -> Reduction
Represents a reduction with no side effects on the model.
Sourcepub fn with_symbols(
new_expression: Expression,
symbols: HashMap<Name, DecisionVariable>,
) -> Reduction
pub fn with_symbols( new_expression: Expression, symbols: HashMap<Name, DecisionVariable>, ) -> Reduction
Represents a reduction that also modifies the symbol table.
Sourcepub fn with_top(new_expression: Expression, new_top: Expression) -> Reduction
pub fn with_top(new_expression: Expression, new_top: Expression) -> Reduction
Represents a reduction that also adds a top-level constraint to the model.
pub fn apply(self, model: &mut Model)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Reduction
impl RefUnwindSafe for Reduction
impl Send for Reduction
impl Sync for Reduction
impl Unpin for Reduction
impl UnwindSafe for Reduction
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§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