summaryrefslogtreecommitdiff
path: root/macros/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-02-10 10:29:17 +0100
committerLaurenz <laurmaedje@gmail.com>2022-02-10 10:29:17 +0100
commit624471db619240f0eed849b92dff6a525ce7e547 (patch)
treeb6218c031019a78a99c7bb99fcbbe40918e6f2d7 /macros/src
parent6e198bf7606847b0847487a4847d6a3ee3621d2d (diff)
Proper error messages for shorthands
Diffstat (limited to 'macros/src')
-rw-r--r--macros/src/lib.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 0757a201..ab9fbf1b 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -56,20 +56,23 @@ fn expand(mut impl_block: syn::ItemImpl) -> Result<TokenStream2> {
let name = property.name;
let string = name.to_string().replace("_", "-").to_lowercase();
- let alternative = if property.variadic {
+ let value = if property.variadic {
quote! {
- .or_else(|| {
- let list: Vec<_> = args.all().collect();
- (!list.is_empty()).then(|| list)
- })
+ match args.named(#string)? {
+ Some(value) => value,
+ None => {
+ let list: Vec<_> = args.all()?;
+ (!list.is_empty()).then(|| list)
+ }
+ }
}
} else if property.shorthand {
- quote! { .or_else(|| args.find()) }
+ quote! { args.named_or_find(#string)? }
} else {
- quote! {}
+ quote! { args.named(#string)? }
};
- quote! { styles.set_opt(Self::#name, args.named(#string)? #alternative); }
+ quote! { styles.set_opt(Self::#name, #value); }
});
parse_quote! {