mdeloof / statig

Hierarchical state machines for designing event-driven systems
https://crates.io/crates/statig
MIT License
560 stars 18 forks source link

Initializing state to a runtime obtained value #25

Closed mattboardman closed 1 week ago

mattboardman commented 1 month ago

My program writes out the current state to a file on every transition. If the program crashes (or needs to be rerun for any other reason) I want to read from the state and initialize the state machine to whatever value is read from the file.

Something like:

let maybe_cached_state: Option<MyState> = read_state_from_file();

if let Some(my_state) = maybe_cached_state {

    let host_machine = MyStateMachine::default()
          .uninitialized_state_machine()
          .init_override(my_state)
          .await;
}

Is there a way to do this with the library or would this be a feature request?

cernicc commented 3 weeks ago

Hey, statig does implement serde. You could probably enable that and directly save the serialized state machine.

mdeloof commented 1 week ago

I'm going to assume that solved your issue. If not, feel free to re-open it 🙂