Skip to content

Commit

Permalink
Define builder with default args
Browse files Browse the repository at this point in the history
  • Loading branch information
l4l committed Jul 25, 2021
1 parent 69d6aac commit 577c894
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/struct_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ impl<'a> StructInfo<'a> {
quote!(#[doc(hidden)])
};

let mut b_decl_generics = b_generics.clone();
for param in &mut b_decl_generics.params {
if let syn::GenericParam::Type(ref mut param) = param {
param.default = Some(empties_tuple.clone().into());
}
}

let (b_generics_impl, b_generics_ty, b_generics_where_extras_predicates) = b_generics.split_for_impl();
let mut b_generics_where: syn::WhereClause = syn::parse2(quote! {
where TypedBuilderFields: Clone
Expand All @@ -149,7 +156,7 @@ impl<'a> StructInfo<'a> {
#[must_use]
#builder_type_doc
#[allow(dead_code, non_camel_case_types, non_snake_case)]
#vis struct #builder_name #b_generics {
#vis struct #builder_name #b_decl_generics {
fields: #all_fields_param,
phantom: (#( #phantom_generics ),*),
}
Expand Down
1 change: 1 addition & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ fn test_builder_name() {
#[derive(TypedBuilder)]
struct Foo {}

let _: FooBuilder = Foo::builder();
let _: FooBuilder<_> = Foo::builder();
}

Expand Down

0 comments on commit 577c894

Please sign in to comment.