News for hackers. Stuff that matters.
Re:Using enums to represent state in Rust by hgomersall on Friday September 22, 2023 @10:53AM (#37612843)
It's less good when the state machine traversal is only known at run time. Necessarily you can only capture the errors at run time, so you get less benefit. You can wrap the states in an enum, but then the enum needs to implement the interface of every state. In that pattern though, you do get the benefit that the enum level dispatcher has to properly obey the types' interface, so you get lots of confidence that the runtime errors will be correct (or at least, an error will happen if the state is called incorrectly).

Still, it's a great pattern that I use as often as I can!

Re:Using enums to represent state in Rust by admax88qqq on Friday September 22, 2023 @08:31PM (#37619516)
Sounds like polymorphism with more steps.

An interface with multiple implementations.