korken89 / smlang-rs

A State Machine Language DSL procedual macro for Rust
Apache License 2.0
202 stars 28 forks source link

Allow for using the same action in multiple transitions #9

Closed jedrzejboczar closed 3 years ago

jedrzejboczar commented 3 years ago

Thanks for this cool library!

In my state machine I have multiple state transitions that require running the same action, but in the current implementation of smlang-rs it results in multiple definitions of an action with the same name in the StateMachineContext trait, so I have to use different name and write some boilerplate code.

I added changes that will allow to use the same action name multiple times and generate only a single method for them. Do you think this is a good feature? My actions/states do not carry any additional data. I guess that with this changes, when someone tries to have to actions that would require different signatures, then the compilation will just fail.

One other thing is that it would be nice if it was possible to derive the Debug trait for Events/States (always? or configurable?). It greatly improves debugging of the state machine behavior and currently I have to implement the trait manually. I also implement Clone for States manually (as my state has no data so could even by Copy). I'm not sure how much effort would it be to be able to also derive it. Maybe some kind of a special syntax at the beginning of the macro?

korken89 commented 3 years ago

Thanks for the PR! Could you add examples so it will test the feature better?

This has been on my TODO but never got around to it, thanks for looking at it! I'll give the feature a spin as well.

Oh, and can you have a look at the failing tests?

jedrzejboczar commented 3 years ago

I added a basic usage example, hope it's ok

korken89 commented 3 years ago

Thanks for the addition!