-
Notifications
You must be signed in to change notification settings - Fork 59
#[builder(setter(transform_generics = "<...>"))]
to add generics to the transform
closure.
#169
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
Conversation
Hi @idanarye, could you please trigger CI when you get a chance? It needs maintainer approval. Thanks! |
Example of new syntax: #[derive(TypedBuilder)]
struct Foo {
#[builder(
setter(
fn transform<'a, M>(value: impl IntoValue<'a, String, M>) -> String
where
M: 'a,
{
value.into_value()
},
)
)]
s: String,
} Existing closure syntax is still supported, so this would still be a minor release |
KeyValue(KeyValue), | ||
Sub(SubAttr), | ||
Not { not: Token![!], name: Ident }, | ||
Fn(syn::ItemFn), |
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.
I'm starting to wonder - maybe instead of ItemFn
this should be generalized as an Item
? Or would that be too hard to work with?
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.
I just tried but it does make it harder to work with, it just requires adding support in a few methods for a lot of variants not currently used. I'd prefer to leave as is unless you feel strongly about it?
Hi @idanarye, this is ready for re-review whenever you're ready :) |
Love the library!
This PR adds a
transform_generics
config to allow adding generic parameters and lifetimes to the closure provided by#[builder(setter(transform = "..."))]
The goal is to be able to replicate this setter:
And with this PR can be done as:
I don't have any preference for this specific syntax, this just seemed to be the simplest non-breaking way to add the functionality, happy to change the implementation if it still adds the same new functionality?
An example of a usecase for this (real usecase in leptos):
With this custom transform setter, I can now use either
T
or|| T