-
Notifications
You must be signed in to change notification settings - Fork 59
Introduce base builder type-alias #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this match all type parameters? The one you want to add a default to is always the first one, so you can just modify that. Or even better - just add the default when creating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that would match all parameters. I guess that barely make sense. Though unfortunately rust doesn't allow to specify defaults for non-trailing generics and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm half minded to just go with your original design as a temporary solution. Once const generics support strings I plan on doing a great refactor that'll break anything (other than regular by-the-book usage) anyway, and once that come I may remove it in favor of something else. |
||
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 | ||
|
@@ -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 ),*), | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this required?
b_generics
is only used when declaring the builder type (and you want the default there) and when splitting it for theimpl
block (where defaults should not be looked at anyway). So why clone it instead of modifying the original?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's redundant, indeed.