Finite state machines in rust; bendns fork to add types.
Diffstat (limited to 'rust_fsm/src/lib.rs')
| -rw-r--r-- | rust_fsm/src/lib.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/rust_fsm/src/lib.rs b/rust_fsm/src/lib.rs index d842311..65c1e13 100644 --- a/rust_fsm/src/lib.rs +++ b/rust_fsm/src/lib.rs @@ -163,16 +163,13 @@ where /// transition. If a state transition with the current state and the /// provided input is not allowed, returns an error. pub fn consume(&mut self, input: &T::Input) -> Result<Option<T::Output>, ()> { - // Operations are reodered for optimization. When the transition is not - // allowed this code exits as soon as possible without calculating the - // output. - let state = match T::transition(&self.state, input) { - Some(state) => state, - None => return Err(()), - }; - let output = T::output(&self.state, input); - self.state = state; - Ok(output) + if let Some(state) = T::transition(&self.state, input) { + let output = T::output(&self.state, input); + self.state = state; + Ok(output) + } else { + Err(()) + } } /// Returns the current state. |