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).
-
Show this thread
-
Definitely not the first person to think of this. But if enums encapsulate state. And all state machines do is describe transitions between states, then if we could specialize on enum members in fn signatures then that would be enough to implement state machines concisely.
5 replies 0 retweets 8 likesShow this thread -
[usual disclaimer I'm not a lang designer, nor on any lang team -- take w/ salt] What I'm thinking is that both examples below are functionally equivalent. I suspect that if we could encode state transitions onto enums it would feel more natural -- e.g. lean into &mut selfpic.twitter.com/5tf49IdDct
4 replies 1 retweet 17 likesShow this thread -
Replying to @yoshuawuyts
There's an issue somewhere for "make enum variants a full type", which I think would make this possible/easier.
2 replies 0 retweets 5 likes -
Replying to @bitshiftmask @yoshuawuyts
https://github.com/rust-lang/rfcs/pull/2593 … (thanks to
@algo_luca, who was independently posting this today again)1 reply 0 retweets 5 likes -
Everybody bumps into it periodically I'd say.
1 reply 0 retweets 7 likes
Interesting that the RFC explicitly mentions disallowing the implementation of methods for specific enum variants. To me that seems like the most useful property (though likely difficult for lang & compiler b/c specialization etc.)
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.