Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Maybe I'm missing something, but it seems that this approach doesn't allow you to store external input that's provided when you transition states.

Say stateB is transitioned to from stateA and needs to store a value that is _not_ directly computed from stateA but is externally supplied at the point of transition.

As far as I understand this isn't possible with the proposed solution? Am I missing something? This seems like a pretty common use case to me.



impl From<(OldState, Input)> for NewState would be one way.


Ok you just blew my mind with this pattern. I created a similar From trait only to take in an extra param so many times. Thanks for this.


Ahh, nice. Didn't think of that!


Hi, I just made a library which does that!

I published first version: https://github.com/michalsustr/rust-automata

Happy to get feedback.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: