Skip to content

Commit

Permalink
Added callback for succesfull transition
Browse files Browse the repository at this point in the history
This patch adds a callback for succesfull transitions. This function can
be used to implement a logging service of some sorts for the state
machine.

Signed-off-by: Martin Broers <[email protected]>
  • Loading branch information
Martin Broers committed Nov 3, 2023
1 parent 9a59f9f commit 8698944
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions macros/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ pub fn generate_code(sm: &ParsedStateMachine) -> proc_macro2::TokenStream {
#guard_list
#action_list
#entry_list

#[allow(missing_docs)]
fn transition_callback(&self, new_state: &Option<#states_type_name>) {}
}

/// List of auto-generated states.
Expand Down Expand Up @@ -588,6 +591,7 @@ pub fn generate_code(sm: &ParsedStateMachine) -> proc_macro2::TokenStream {
#(#events_type_name::#events => {
#code_blocks

self.context().transition_callback(&self.state);
self.state()
}),*
_ => {
Expand Down

0 comments on commit 8698944

Please sign in to comment.