Functional State Machines in Rust: Typestate and Newtype Patterns
matt_d
72 points
29 comments
August 29, 2026
Related Discussions
Found 5 related stories in 66.8ms across 4,895 title embeddings via pgvector HNSW
- Scaling Memory Safety: AI-Assisted Rewrites of C/C++ Dependencies to Rust afdbcreid · 15 pts · August 24, 2026 · 47% similar
- Rust Glancer surprisetalk · 30 pts · August 21, 2026 · 46% similar
- StateM: Stateful Control for Long-Horizon Agents johntrob14 · 11 pts · August 24, 2026 · 45% similar
- Rust 1.98.0 thesuperbigfrog · 17 pts · August 20, 2026 · 44% similar
- Topcoat: The full full-stack framework for Rust wertyk · 66 pts · July 17, 2026 · 44% similar
Discussion Highlights (6 comments)
michaelnoguera
pdf: https://dl.acm.org/doi/pdf/10.1145/3830438.3830958
vatsachak
Types are puzzles. A good Rustacean will make sure that the pieces fit to make the picture. That's why in crates where I need to make sure certain functions are called in order, I use a Ticket<T>, where one function returns a Ticket<Func1Done> with the output and the other has to consume it as an input. The typestate pattern is a specialization of making only valid states representable
arpinum
I use Typestates and Newtypes extensively. The metric that shows Typestate and Newtypes are beneficial is: How many method calls or parameters can be called / used that compile but are not valid use cases. You want to minimise this number. I love having a type state where I can only make 1 or 2 method calls because the state enforces there are only a few parsing / validation / transition methods available. And there is only one valid way to supply the parameters, I cannot use the strings in the wrong location. I only wish we had named parameters like ObjC.
doyougnu
This was a talk at the FUNARCH workshop at this year’s ICFP. Here’s the livestream: https://www.youtube.com/live/c0pw1iVs_Q0?is=hwm2xa4cZOcqF5tW Well post the individual talks in the following days!
sourdecor
Could someone compare this to ST in Idris?
bana-io
Maybe I am missing something but where is the entire source code?