Skip to content

Commit

Permalink
remove the need of importing Props structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed Sep 11, 2023
1 parent de58fcc commit b6f01d5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
13 changes: 8 additions & 5 deletions rscx-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions rscx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod attributes;
pub mod props;
pub use attributes::*;

#[cfg(feature = "axum")]
Expand Down
21 changes: 21 additions & 0 deletions rscx/src/props.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub trait Component<P> {}

impl<P, F, R> Component<P> for F
where
F: FnOnce(P) -> R,
P: Props,
{
}

pub fn props_builder<C, P>(_: C) -> P::Builder
where
C: Component<P>,
P: Props,
{
P::builder()
}

pub trait Props {
type Builder;
fn builder() -> Self::Builder;
}

0 comments on commit b6f01d5

Please sign in to comment.