A presentation which introduces a few different techniques for implementing state machines in Rust.
-
tennis kata
- naive implementation
- naive implementation using enumeration for score
- a state machine solution
- fixing problems with naive solution
- another state machine solution
- uses minimal memory
- uses type system to prevent invalid transitions
- iterating on 20-state solution to replace big match statement with a dynamic dyn call
- improves performance
- reduces cognitive load
- iterating on 20-state solution to replace big match statement with a table lookup
- improves performance over big match statements
- best performance?
- reduces cognitive load
-
- redemonstrate technique from tennis kata on simple state machine
-
- useful idiom for implementing stateful interfaces
- prevents incorrect use of stateful interfaces
-
asynchronous state machine parser
- a state machine driven parser
- uses function pointers to force a jump table
Use graphviz to generate images for tennis kata state machines:
$ circo -Tpng -o sm4.png sm4.dot
$ dot -Tpng -o sm20.png sm20.dot
$ dot -Tpng -o simple.png simple.dot
View the images using feh:
$ feh -Z -F sm4.png
$ feh -Z -F sm20.png
$ feh -Z -f simple.png
The slides can be generated using TexMaker.
The code slides require bat and ksh and can be viewed by running ./code_slides.sh
Configure secondary monitor to mirror the main monitor using xrandr:
$ xrandr --output SECONDARY --same-as PRIMARY
Where SECONDARY is the name of the second monitor and PRIMARY is the name of the primary monitor.