playground link if you want to try it: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9ac3f0d23b98a28dd94e12fb0f1a30ab … This is def one of those cases where Rust's typesystem feels like magic to me.
-
-
Show this thread
-
For anyone wondering: "what am I looking at?" It's a state machine for a traffic light, checked at compile time. Green -> Yellow -> Red -> Green by triggering the "next" event on it (e.g. calling a method).
Show this thread
End of conversation
New conversation -
-
-
A while back I wrote https://github.com/fitzgen/state_machine_future … which you might find interesting; would be cool if someone ported it to std futures! ;)
-
Haa yeah I linked to it from the post! :D
- 5 more replies
New conversation -
-
-
What's the bit you would expect not to work?
-
Oh I didn't expect any of this to *not* work; but it's more that I only recently realized that encoding compiler-checked state machines in Rust is not only possible, we've been doing it all along. All we're missing really is better syntax, and I suspect enums can provide.
- 4 more replies
New conversation -
-
-
Rust Beginner Question: Is having two `impl State<Green>` there different than having one `impl` with both methods inside? This seems to work also, but I would love to know if there is a difference: Thanks!pic.twitter.com/6OfQRJT6OU
-
What you typed is valid and the same thing. Them being separated in the example has no particular reasoning behind it.
- 2 more replies
New conversation -
-
-
Nit: you don't need `{}` after struct literals for structs without fields. Just State { _inner: Green } works too.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
No
State 
-
How does anarchism work? I want to learn.
- 12 more replies
New conversation -
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.