Get the latest tech news
Pretty State Machine Patterns in Rust (2016)
A computer scientist working in open source towards a more hopeful future.
As we saw above the most natural way to attempt this is an enum, but we noted already that you can't control which transitions are actually permitted in this case. Indeed, the entire structure is consumed so if there are side effects of the transition on the parent (for example altering the average waiting time) we can't access stale values. If you recall the primary problem with the enum example above was that we had to deal with no ability to enforce transitions, and the only errors we got were at runtime when we did try.
Or read this on Hacker News