Skip to content

Commit

Permalink
Get current state as option, no more panicking at the end of a machine
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Boyle committed Aug 5, 2024
1 parent d441dd0 commit 7d6d385
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ impl StateMachine {
}
}

pub fn current_state(&self) -> String {
self.current_state.as_ref().unwrap().name().clone()
pub fn current_state(&self) -> Option<String> {
match self.current_state.as_ref() {
Some(s) => Some(s.name().clone()),
None => None
}
}

pub fn run<I: Serialize, O: DeserializeOwned>(&mut self, i: I) -> SML_Result<Option<O>> {
Expand Down

0 comments on commit 7d6d385

Please sign in to comment.