Closed thejpster closed 2 months ago
For now one need to put the macro in separate modules, but if you check the TODO in the readme - what do you think about the proposed syntex for setting name?
For now, the recommended action is:
mod vend_product {
statemachine! {
*State1 + Event1 [guard] / action1 = State2,
State2 + Event2 [guard_fail] / action2 = State3,
}
}
mod handle_money {
statemachine! {
*State1 + Event1 [guard] / action1 = State2,
State2 + Event2 [guard_fail] / action2 = State3,
}
}
fn run() {
let fsm1 = vend_product::StateMachine::new();
let fsm2 = handle_money::StateMachine::new();
}
I like the syntax proposed by @thejpster. I could design the macro so that, if a name is provided, it generates the state machine code in a dedicated mod{} the the name provides but if a name is not provided, it will generate the code in the same the existing file namespace so it shouldn't break anything.
Unless there are any objections, I will pursue integrating this into a 0.5.0 release candidate along with some other features.
I believe this is fixed by https://github.com/korken89/smlang-rs/pull/62, where you can provide a name
parameter in the DSL. This gives all the traits/states/events a prefix to allow them all to exist in the same file/mod (as long as they have unique names)
Is it possible to create multiple different statemachines in one file? e.g.
Does putting them in a module act as a workaround?