(no title)
phibz | 10 months ago
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.
jelder|10 months ago
wging|10 months ago
zokier|10 months ago
Tbh it would make interesting blog post to compare modern typestate patterns to the historical built-in typestate mechanism.
https://github.com/rust-lang/rust/issues/2178