Rust: Pushdown Automata
Implementing a Simple State Machine in Rust
Rust is a really great language. It’s a real pain to get to know the borrow checker, but once you get past that hurdle you can start making some cool things. Today I’d like to discuss how we can make a variant of Finite State Machine known as the Pushdown Automata — in Rust!
Let’s discuss what a Finite State Machine is, first of all. Imagine an application, like a web app client possibly. This application has a variety of states that it can exist in at any point, and only one of those states may be the active state at any given time. If we can determine and define each possible state, we can create a Finite State Machine out of the set of states. A Finite State Machine is the collection of all possible states and their possible transitions. Let’s write an enum
that will house our state data.
So that tells us pretty much nothing. But don’t worry, we’ll add variants and implementation soon enough. Let’s now discuss the specific Pushdown Automata variant of the Finite State Machine. When a State Machine needs to remember it’s previous states, we can push them down into the State Machine mechanism. Then when we are…