You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[freezable]fnmy_func(){loop{let a = 3;freeze!()let b = a + 2;let user_input = take_user_input_here();if user_input == b {break}}}
with our current approach, we are creating a new state after each freeze!(). However, in the above code, there are indefinite amount of freeze!()s. That means, we have to create an enum with infinite states, which is not possible.
The text was updated successfully, but these errors were encountered:
Currently, our approach is to parse the function, create the statemachine, and get rid of the function. The whole thing will turn into an enum representing the statemachine, and this very enum will implement the freezable trait and its methods. This approach clearly does not work if the freezable content is inside a loop.
Instead, we can do the following:
locate the code block(s) that contains freeze!() statement(s)
turn these code blocks into the statemachines
locate the outer code block, and turn them into statemachines as well, which can work like this:
storing the innerStateMachine (which is the inner block StateMachine enum) as one of the states
other states should be Next and LoopFinished
when innerStateMachine is Finished, proceed into Next state
Next state checks whether the loop should continue or is it finished
if loop should continue, set innerStateMachine to its beginning state, and switch to innerStateMachine
if loop should finish, proceed to LoopFinished state
Imagine below:
with our current approach, we are creating a new state after each
freeze!()
. However, in the above code, there are indefinite amount offreeze!()
s. That means, we have to create anenum
with infinite states, which is not possible.The text was updated successfully, but these errors were encountered: