-
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
Changes from all commits
617e784
3bc5542
5a387eb
9218f5a
6a30439
13adb32
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ members = [".", "./typed-builder-macro"] | |
|
||
[workspace.package] | ||
description = "Compile-time type-checked builder derive" | ||
version = "0.21.2" | ||
version = "0.21.3" | ||
authors = ["IdanArye <[email protected]>", "Chris Morgan <[email protected]>"] | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
|
@@ -27,4 +27,4 @@ keywords.workspace = true | |
categories.workspace = true | ||
|
||
[dependencies] | ||
typed-builder-macro = { path = "typed-builder-macro", version = "=0.21.2" } | ||
typed-builder-macro = { path = "typed-builder-macro", version = "=0.21.3" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ pub enum AttrArg { | |
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 commentThe reason will be displayed to describe this comment to others. Learn more. I'm starting to wonder - maybe instead of 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 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? |
||
} | ||
|
||
impl AttrArg { | ||
|
@@ -124,6 +125,7 @@ impl AttrArg { | |
AttrArg::KeyValue(KeyValue { name, .. }) => name, | ||
AttrArg::Sub(SubAttr { name, .. }) => name, | ||
AttrArg::Not { name, .. } => name, | ||
AttrArg::Fn(func) => &func.sig.ident, | ||
} | ||
} | ||
|
||
|
@@ -133,6 +135,7 @@ impl AttrArg { | |
AttrArg::KeyValue(KeyValue { name, .. }) => format!("{:?} is not supported as key-value", name.to_string()), | ||
AttrArg::Sub(SubAttr { name, .. }) => format!("{:?} is not supported as nested attribute", name.to_string()), | ||
AttrArg::Not { name, .. } => format!("{:?} cannot be nullified", name.to_string()), | ||
AttrArg::Fn(func) => format!("{:?} is not supported as a function", func.sig.ident.to_string()), | ||
}; | ||
syn::Error::new_spanned(self, message) | ||
} | ||
|
@@ -308,6 +311,11 @@ fn get_token_stream_up_to_cursor(input: syn::parse::ParseStream, cursor: syn::bu | |
|
||
impl Parse for AttrArg { | ||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> { | ||
// Check for standalone function first | ||
if input.peek(Token![fn]) { | ||
return Ok(Self::Fn(input.parse()?)); | ||
} | ||
|
||
if input.peek(Token![!]) { | ||
Ok(Self::Not { | ||
not: input.parse()?, | ||
|
@@ -325,8 +333,6 @@ impl Parse for AttrArg { | |
args: args.parse()?, | ||
})) | ||
} else if input.peek(Token![=]) { | ||
// Try parsing as a type first, because it _should_ be simpler | ||
|
||
Ok(Self::KeyValue(KeyValue { | ||
name, | ||
eq: input.parse()?, | ||
|
@@ -337,7 +343,7 @@ impl Parse for AttrArg { | |
}, | ||
})) | ||
} else { | ||
Err(input.error("expected !<ident>, <ident>=<value> or <ident>(…)")) | ||
Err(input.error("expected !<ident>, <ident>=<value>, <ident>(…), or fn")) | ||
} | ||
} | ||
} | ||
|
@@ -353,6 +359,7 @@ impl ToTokens for AttrArg { | |
not.to_tokens(tokens); | ||
name.to_tokens(tokens); | ||
} | ||
AttrArg::Fn(func) => func.to_tokens(tokens), | ||
} | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.