pub struct Action {
variable_to_update: Variable,
update_expr: UpdateExpression,
}Expand description
Action on a shared variables
This struct defines action in a GeneralThresholdAutomaton, describing
how executing a rule will update a shared variable.
Fields§
§variable_to_update: VariableVariable to be updated
update_expr: UpdateExpressionExpression specifying the update rule
Implementations§
Source§impl Action
impl Action
Sourcefn count_number_of_var_occurrences_and_validate(
var: &Variable,
update_expr: &IntegerExpression<Variable>,
) -> Result<u32, InvalidUpdateError>
fn count_number_of_var_occurrences_and_validate( var: &Variable, update_expr: &IntegerExpression<Variable>, ) -> Result<u32, InvalidUpdateError>
This function counts the number of occurrences of variable var in the
expression and checks that no parameters appear
If a parameter or a variable that is not var is found in the
expression, an error is returned
Sourcefn parse_to_update_expr(
var: &Variable,
update_expr: IntegerExpression<Variable>,
) -> Result<UpdateExpression, ActionBuilderError>
fn parse_to_update_expr( var: &Variable, update_expr: IntegerExpression<Variable>, ) -> Result<UpdateExpression, ActionBuilderError>
Try to parse a general integer expression into an update expression
Sourcepub fn new_reset(to_update: Variable) -> Self
pub fn new_reset(to_update: Variable) -> Self
Create a new reset action which a reset of var_to_update.
§Example
use taco_threshold_automaton::general_threshold_automaton::Action;
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
// action resetting var1
Action::new_reset(Variable::new("var1"));Sourcepub fn new(
to_update: Variable,
update_expr: IntegerExpression<Variable>,
) -> Result<Self, ActionBuilderError>
pub fn new( to_update: Variable, update_expr: IntegerExpression<Variable>, ) -> Result<Self, ActionBuilderError>
Create a new action that updates variable var_to_update with the
result of update_expr
Returns an error if the update expression is malformed, e.g. if the update refers to a different variable than the one to update.
§Example
use taco_threshold_automaton::general_threshold_automaton::Action;
use taco_threshold_automaton::expressions::*;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
// action incrementing var1
Action::new(
Variable::new("var1"),
IntegerExpression::Const(1)
+ IntegerExpression::Atom(Variable::new("var1")),
).unwrap();Sourcepub fn new_with_update(var: Variable, update: UpdateExpression) -> Self
pub fn new_with_update(var: Variable, update: UpdateExpression) -> Self
Create a new action that updates variable var according to update
§Example
use taco_threshold_automaton::general_threshold_automaton::Action;
use taco_threshold_automaton::general_threshold_automaton::UpdateExpression;
use taco_threshold_automaton::expressions::Variable;
use taco_threshold_automaton::general_threshold_automaton::builder::*;
// action incrementing var1
Action::new_with_update(
Variable::new("var1"),
UpdateExpression::Inc(1),
);