korken89 / smlang-rs

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

unable to initialize statemachine with current state #19

Closed vidyli closed 3 years ago

vidyli commented 3 years ago

I am a littler curious why we can't specify state when creating Statemachine, for example, we may load the state from a database , Cart -> New -> Completed.

 impl<T: StateMachineContext> StateMachine<T> {
            /// Creates a new state machine with the specified starting state.
            #[inline(always)]
            pub fn new(context: T) -> Self {
                StateMachine {
                    state: States::#starting_state,
                    context
                }
            }

          //...
}
Yatekii commented 3 years ago

I think this is just something that was not used yet :) I guess most state machines are run from the same initial state every time. You can easily have a "sytsem boot" state which then goes to the correct state immediately :)

I see the advantages of targeted state creation tho! So adding this would be welcome imo.

korken89 commented 3 years ago

Fixed in #20