-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Simplify processing of structured MetaItems #25
Comments
Something like this in this case: if let attr_pat!{ #[_(treat_none_as_null = "true")] } = options_attr {
true
} else {
usage_err()
} or: if let attr_pat!{ #[_(treat_none_as_null = ref value)] } = options_attr {
value == "true"
} else {
usage_err()
} |
Interesting idea to use a macro for this. The macro as you described it above looks for this explicit pattern, right? How'd you handle the default case, i.e., the option we are looking for is not set (but maybe others are)? I'd've suggested introducing a special attr type for attrs that are like let changeset_options: OptionsAttr =
macro_input
.attr("changeset_options")
.parse_as_options_attr()
.unwrap_or_else(usage_error);
let treat_none_as_null =
changeset_options
.boolean_field("treat_none_as_null")
.unwrap_or(false); |
One easy win would be to drop |
Here is a neat idea from @killercup in colin-kiegel/rust-derive-builder#32 - use Serde!
|
I wrote a little procedural macro crate for parsing attributes
|
Amazing. I'm happy to recommend prom-attire as the solution to this. Thanks @Nemo157! |
Diesel uses the following to parse attributes of the form
#[changeset_options(treat_none_as_null = "true")]
:I expect this use case to be pretty common so let's provide helpers to make it less bad.
The text was updated successfully, but these errors were encountered: