Oooops, accidentally spent most of the afternoon thinking about state machines instead of working on my talk. Think I'm onto something fun though (and probably should write in a longer fashion about it at some point).
-
-
Oh lol; the second example doesn't have enough information to track what it transitions into. The signature implies this is valid: if x { *self = Self::A } else { *self = Self::B } The point is that this can't happen. Either compiler should infer, or syntax is needed. Oops.
Show this thread -
Yeah maybe the answer is that it only works for Self::A -> Self::B, taking ownership of Self each time. I mean, it's not perfect but it would remove a lot of boilerplate when trying to store the states inside another struct (something the first example doesn't even try).
Show this thread
End of conversation
New conversation -
-
-
There's an issue somewhere for "make enum variants a full type", which I think would make this possible/easier.
-
https://github.com/rust-lang/rfcs/pull/2593 … (thanks to
@algo_luca, who was independently posting this today again) - 2 more replies
New conversation -
-
-
I really wish that enum variants were real types

-
Your left side provides "session types" that express the state transition at the type level. Actually doing this with the right side requires fn next(self: State::Green) -> State::Yellow plus NRVO.
- 2 more replies
New conversation -
-
-
The second example reminds me of function based pattern matching in
#Erlang <3 I would quite enjoy having that in rust!Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.