4 ms·
> We naturally use Rust enums to describe these states. How nice it would be if Rust's enum system was rich enough to be able to describe and enforce the valid
by estebank 3y ago
> We naturally use Rust enums to describe these states. How nice it would be if Rust's enum system was rich enough to be able to describe and enforce the valid state transitions rather than just the set of possible states. There are various ways to try and approximate this (I've seen a few articles), but on the whole they're rather awkward and full of holes.
I'm assuming you're referring to type state machines, where you have one struct per state and the only way to translate from one state to the next is through method calls. Defining these is quite verbose (unless you rely on macros) but how is it full of holes?
- cmrdporcupine 3y agoIn that case: Potential holes because the permitted state transitions are scattered through function signatures and not described in a centralized place. You're right macros could make this more pleasant. I still think it's quite unergonomic. But yes, I probably should have said "awkward and/or full of holes" instead of and