You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, usually, do_woobah doesn't have a meta list, the default config values are enough most of the time.
#[do_woobah]fnwobble_function(){}
This fails to compile when using syn::meta::parser. To me, it doesn't make sense that this should fail. I don't see the interest in failing on an empty meta list.
Say you have mandatory config options. Regardless of whether the options are mandatory or not, you still need to check afterward that all mandatory config options are set, and ideally tell the user what to options are missing, so this behavior is unwishable in this case as well.
Workaround
Thankfully, TokenStream exposes a is_empty() method, and I can use it to avoid running syn::meta::parse when attrs is empty:
pubfndo_woobah(attrs:TokenStream1,input:TokenStream1) -> TokenStream1{letmut config = Config::default();if !attrs.is_empty(){let config_parser = syn::meta::parser(|meta| config.parse(meta));parse_macro_input!(attrs with config_parser);}// Use `config` here}
The text was updated successfully, but these errors were encountered:
My
#[proc_macro_attribute]
optionally accepts config flags as a meta list. So I usedsyn
'ssyn::meta::parser
to read the attributes.However, it fails when the meta list is empty, with no way of controlling this behavior.
Say I have a
Config
struct as follow:I have a parse method on
Config
as follow, similar to the one in the doc example:I will use
syn::meta::parser
as follow:I can call
do_woobah
as follow:However, usually,
do_woobah
doesn't have a meta list, the default config values are enough most of the time.This fails to compile when using
syn::meta::parser
. To me, it doesn't make sense that this should fail. I don't see the interest in failing on an empty meta list.Say you have mandatory config options. Regardless of whether the options are mandatory or not, you still need to check afterward that all mandatory config options are set, and ideally tell the user what to options are missing, so this behavior is unwishable in this case as well.
Workaround
Thankfully,
TokenStream
exposes ais_empty()
method, and I can use it to avoid runningsyn::meta::parse
whenattrs
is empty:The text was updated successfully, but these errors were encountered: