diff --git a/rscx-macros/src/lib.rs b/rscx-macros/src/lib.rs index da540ef..6e9341f 100644 --- a/rscx-macros/src/lib.rs +++ b/rscx-macros/src/lib.rs @@ -297,13 +297,9 @@ impl<'e> CustomElement<'e> { impl<'e> ToTokens for CustomElement<'_> { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { let name = self.e.name(); - let props_struct_name = syn::Ident::new( - &format!("{}Props", name.to_string()), - proc_macro2::Span::call_site(), - ); let mut chain = vec![quote! { - #props_struct_name::builder() + ::rscx::props::props_builder(name) }]; let children = &self.e.children; @@ -374,6 +370,13 @@ impl ToTokens for PropsStruct { #[derive(::rscx::typed_builder::TypedBuilder)] #[builder(doc, crate_module_path=::rscx::typed_builder)] #item + + impl ::rscx::props::Props for #name { + type Builder = #builder_name; + fn builder() -> Self::Builder { + #name::builder() + } + } }); let has_attributes = item diff --git a/rscx/src/lib.rs b/rscx/src/lib.rs index 17f26c7..572cdd7 100644 --- a/rscx/src/lib.rs +++ b/rscx/src/lib.rs @@ -1,4 +1,5 @@ pub mod attributes; +pub mod props; pub use attributes::*; #[cfg(feature = "axum")] diff --git a/rscx/src/props.rs b/rscx/src/props.rs new file mode 100644 index 0000000..7572fc8 --- /dev/null +++ b/rscx/src/props.rs @@ -0,0 +1,21 @@ +pub trait Component
{} + +impl
Component
for F
+where
+ F: FnOnce(P) -> R,
+ P: Props,
+{
+}
+
+pub fn props_builder ,
+ P: Props,
+{
+ P::builder()
+}
+
+pub trait Props {
+ type Builder;
+ fn builder() -> Self::Builder;
+}