-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Would be awesome to have an attribute that draws an ASCII picture of the resulting tree #11
Comments
I definitely want to add some way to visualise the state machines, though I'm still thinking about the best way to go about it. The tree representation is a nice start and should be pretty easy to do, but it doesn't include the possible transitions in response to events. Because that logic is defined as Rust code it's almost impossible to derive that reliably, so I'm thinking of maybe adding a way to annotate your state machines to provide that information to the visualiser. I've been considering something like this, though I'm still not completely happy with it. #[state]
fn led_on(&mut self, event: &Event) -> Response<State> {
match event {
#[event(transition(led_off))]
Event::TimerElapsed => {
self.led = false;
Transition(State::led_off())
}
#[event(transition(not_blinking))]
Event::ButtonPressed => Transition(State::not_blinking())
}
} So yeah, maybe I'll just start with tree and go from there. |
I'd love this feature too. I have been trying multiple state machine crates to enforce some safety between transitions with not too much boilerplate. I find that |
To solve the „retrieve transitions from code problem“, wouldn’t one solution be to add the possible target states for a certain state within the states macro above the function signature? I think that would be a bit more brief than adding a macro to each returned value. One could even generate an Enum that has to be returned from the state instead of the „States“ enum thats containing all states. This of course wouldn’t prevent transitions from never happen but it would make sure that the generated graph contains all possible transitions. Something like: #[state(target_states=[StateB, StateC])]
fn state_a(…) -> Response<StateAOut> {…} |
Is there something that makes this hard to construct dynamically? for each state... Then once you have that graph, use graph algorithms from the graph libarary to do visualization, reachability analysis, etc... This would work for pure state machines that only transition in response to events, but since users can stick arbitrary logic in their event handler functions (including non-deterministic transitions), so maybe that's not a solution for everyone. This is something I might be able to get budget to work on and upstream; we're considering using statig for a project at my work. Thanks! |
Yes, like you said, you would have to place some restrictions on the logic in the event handlers to make sure this approach is able to correctly cover the entire state machine. I'm not sure then if it would be the best fit with statig, but I also don't see a better solution for the moment. Nice to hear that you're considering to use it at your work. Always cool to see other Belgian companies using Rust! |
Thinking something like
Which would print something like
The text was updated successfully, but these errors were encountered: