4/20/2025 at 6:35:59 AM
I'm a bit surprised that they don't use the name "type state". Perhaps it wasn't in wide use when this post was originally written?The important ideas here are that each state is moved in to the method that transitions to the next state. This way you're "giving away" your ownership of the data. This is great for preventing errors. You cannot retain access to stale state.
And by using the From trait to implement transitions, you ensure that improper transitions are impossible to represent.
It's a great pattern and has only grown in use since this was written.
by phibz
4/20/2025 at 2:18:03 PM
Just a Nine Inch Nails fan who really wanted the title to be a pun on “Pretty Hate Machine.”by jelder
4/20/2025 at 6:43:10 AM
I think I first learned of that term from this 2019 article: https://cliffle.com/blog/rust-typestate/ I can't be the only one...by wging
4/20/2025 at 9:32:11 AM
Typestates were also notable feature in early Rust, albeit in a very different form. I do recall them mentioned often in presentations/talks/etc at the time.Tbh it would make interesting blog post to compare modern typestate patterns to the historical built-in typestate mechanism.
by zokier