Skip to content

Commit

Permalink
renamed GuardError to ErrorType to be used with both guards and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Kumshayev committed Jun 27, 2024
1 parent 23c3bdc commit 364914d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/guard_custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ statemachine! {
pub struct Context;

impl StateMachineContext for Context {
type GuardError = GuardError; // Guard1 has access to the data from Event1
type ErrorType = GuardError; // Guard1 has access to the data from Event1
fn guard1(&self, _event_data: &MyEventData) -> Result<bool, GuardError> {
Err(GuardError::Custom)
}
Expand Down
10 changes: 5 additions & 5 deletions macros/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub fn generate_code(sm: &ParsedStateMachine) -> proc_macro2::TokenStream {
.collect();

let guard_error = if sm.custom_guard_error {
quote! { Self::GuardError }
quote! { Self::ErrorType }
} else {
quote! { () }
};
Expand Down Expand Up @@ -518,15 +518,15 @@ pub fn generate_code(sm: &ParsedStateMachine) -> proc_macro2::TokenStream {

let guard_error = if sm.custom_guard_error {
quote! {
/// The error type returned by guard functions.
type GuardError: core::fmt::Debug;
/// The error type returned by guard or action functions.
type ErrorType: core::fmt::Debug;
}
} else {
quote! {}
};

let guard_error_type = if sm.custom_guard_error {
quote! { Self::GuardError }
quote! { Self::ErrorType }
} else {
quote! { () }
};
Expand All @@ -539,7 +539,7 @@ pub fn generate_code(sm: &ParsedStateMachine) -> proc_macro2::TokenStream {

let error_type = if sm.custom_guard_error {
quote! {
#error_type_name<<T as #state_machine_context_type_name>::GuardError>
#error_type_name<<T as #state_machine_context_type_name>::ErrorType>
}
} else {
quote! {#error_type_name}
Expand Down

0 comments on commit 364914d

Please sign in to comment.