diff --git a/CHANGELOG.md b/CHANGELOG.md index 12e6c4c..7e2469c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [breaking] Actions now take owned values - [breaking] `state()` now returns a `Result` +- `StateMachine::new` and `StateMachine::new_with_state` are now const functions ## [v0.6.0] - 2022-11-02 diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 8a32918..bf2d813 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -410,7 +410,7 @@ pub fn generate_code(sm: &ParsedStateMachine) -> proc_macro2::TokenStream { let starting_state_name = starting_state.to_string(); let new_sm_code = match sm.state_data.data_types.get(&starting_state_name) { Some(st) => quote! { - pub fn new(context: T, state_data: #st ) -> Self { + pub const fn new(context: T, state_data: #st ) -> Self { StateMachine { state: Some(States::#starting_state (state_data)), context @@ -418,7 +418,7 @@ pub fn generate_code(sm: &ParsedStateMachine) -> proc_macro2::TokenStream { } }, None => quote! { - pub fn new(context: T ) -> Self { + pub const fn new(context: T ) -> Self { StateMachine { state: Some(States::#starting_state), context @@ -521,7 +521,7 @@ pub fn generate_code(sm: &ParsedStateMachine) -> proc_macro2::TokenStream { /// Creates a new state machine with an initial state. #[inline(always)] - pub fn new_with_state(context: T, initial_state: States <#state_lifetimes_code>) -> Self { + pub const fn new_with_state(context: T, initial_state: States <#state_lifetimes_code>) -> Self { StateMachine { state: Some(initial_state), context