korken89 / smlang-rs

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

Feature: use same guard function in multiple places #10

Closed andresv closed 3 years ago

andresv commented 3 years ago

Here I have parse_response function that is actually the same for all responses. It would be good if this can be used in multiple places like that:

statemachine! {
    *StateInit + Init / exit_command_mode = StateExitCmdMode,
    // exit cmd mode
    StateExitCmdMode + RxByte(u8) [parse_response] / enter_command_mode = StateEnterCmdMode,
    StateExitCmdMode + Timeout = StateEnterCmdMode,

    // enter cmd mode
    StateEnterCmdMode + RxByte(u8) [parse_response] = StateIdle,
    StateEnterCmdMode + Timeout = StateIdle,

    StateIdle + Event = StateIdle
}
korken89 commented 3 years ago

Hi, this should be possible! If you want to give it a try, you can have a look at the latest PR that did thus but for actions. I think it should mostly be a copy/paste exercise :)