
A Finite State Machine in Rust (part 2)
Implementing a Finite State Machine in Rust
This is part 2 in a series… see here for part 1.
Description
This is a scaled down version of what I created for a customer. It is just a VERY simple example of the steps in which a user might log in, get authenticated and send data. Note: you will not learn anything technical or get any details regarding how to setup, authenticate, and send data as a user. The purpose is to see the state transitions from one to another and how the finite state machine moves you from start to finish.
The valid states in this example are:
- connect
- auth alice
- data A (send a single character)
- data hello world (send message)
- disconnect
- quit
As this is a finite state machine, you can only advance in a set order. That order is as specified above. This means that you are not able to advance from one state to another randomly. Status is returned as you enter the state name - if you progress to a valid state, a status of zero is returned. For an invalid state transition, a minus one is returned.
How to run
This is the quick explanation. I will later provide a more detailed explanation as to how you would install and compile a rust program using cargo.
For now, assuming you have rust installed:
cargo new
cargo run
How does this work?
Have questions or want to share your own sysadmin story? Leave a comment below!
(I will set up comments eventually ;)