Thoughts on Sequenced State Machines

So, the boot machine works well because the type is always known:


#![allow(unused)]
fn main() {
fn(&mut Self) -> Result<bool, E>;
}

However, this generally forces runtime checking to be:

  • up to the user to state and verify preconditions
  • potentially faulty at runtime

I could end up doing something like async/await, but that requires (probably) boxing

I can sort of see this as a tree of states, with each leaf state specifying a "goto" (for lack of a better word) of where on the graph to return to.

The queue doesn't play well with different types, unless I use dynamic dispatch.

I don't want to repeatedly pay checking costs, on state transition might be okay.

I wonder if I'm just looking for generators.

I already have the control flow and nodes stored, I wonder if there was a more type safe way I could define the states and transitions.

How can I make sure that the sequences ONLY describe an acceptable flow? e.g

A
    -> B
B
    -> C
    -> D
C
    -> A
    -> D
D
    -> B
    -> A

Hmm, this can also describe success and error conditions, but also many success conditions?

Is this just HSMs with de-duplicated common trees?

Sequences:

  • AB

Subroutines and States

Maybe it makes sense to separate states (which only schedule), vs subroutines, which strictly perform nonblocking actions.

Basically in my boot machine code now, any code that sets the state queue, should be a state. Anything that doesn't, is a subroutine, or part of a subroutine.