Skip to content

Commit

Permalink
feat: added support for #[make_rx(...)] on unit structs
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Jan 30, 2022
1 parent 1570e5d commit cb2f49d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/perseus-macro/src/rx_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,9 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream {
"tuple structs can't be made reactive with this macro (try using named fields instead)",
)
.to_compile_error(),
syn::Fields::Unit => {
return syn::Error::new_spanned(
new_struct,
"it's pointless to make a unit struct reactive since it has no fields",
)
.to_compile_error()
}
// We may well need a unit struct for templates that use global state but don't have proper state of their own
// We don't need to modify any fields
syn::Fields::Unit => (),
};

// Create a list of fields for the `.make_rx()` method
Expand All @@ -147,6 +143,7 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream {
}
}
}
syn::Fields::Unit => quote!(#name),
// We filtered out the other types before
_ => unreachable!(),
};
Expand Down Expand Up @@ -174,6 +171,7 @@ pub fn make_rx_impl(mut orig_struct: ItemStruct, name: Ident) -> TokenStream {
}
}
}
syn::Fields::Unit => quote!(#ident),
// We filtered out the other types before
_ => unreachable!(),
};
Expand Down

0 comments on commit cb2f49d

Please sign in to comment.