korken89 / smlang-rs

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

Why is the StateMachine::new not a const function? #45

Closed tolgaparlan closed 2 years ago

tolgaparlan commented 2 years ago

I am using this library in an interrupt in an embedded project. I wanted to take advantage of the fact that static mut can be safely used in interrupt/exception contexts. However I cannot do something like:

#[interrupt]
fn TIM2() {
    static mut sm: StateMachine<Context> = StateMachine::new(Context::new_const_default());
...}

because StateMachine::new is not a const function. I have to wrap it in a Option, adding an unnecessary check at each interrupt call. Can something be done to enhance this given that a no-std library like this is going to see a lot of embedded usage?