-
Notifications
You must be signed in to change notification settings - Fork 89
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
Reimplement attribute parsing without darling
#310
Conversation
--> tests/compile-fail/build_fn_error.rs:4:52 | ||
| | ||
4 | #[builder(build_fn(error(validation_error = false, path = "hello")))] | ||
| ^^^^ | ||
|
||
error: Cannot set `error(validation_error = false)` when using `validate` | ||
--> tests/compile-fail/build_fn_error.rs:10:45 | ||
error: `error(validation_error = false)` cannot be set when using `validate` |
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.
if validate = "hello"
is highlighted below then shouldn't this say something like "validate
cannot be set if error(validation_error = false)
is used"? :)
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.
Good call. I updated the PR rewording it to "error(validation_error = false)
and validate
cannot be used together" which is consistent with wording that is already used prior to this PR when dealing with the conflict between builder(default)
and builder(field(build = "..."))
.
5bdc593
to
1733f00
Compare
Acknowledging receipt of PR. |
Rebased on #311 to fix nightly CI. |
This finally gave me the push needed to get
We'd previously discussed this in dtolnay/syn#1458, and my impression was that not accepting
With the introduction of Since those checks are part of the generated darling impl via the use of
I view these as a benefit, not a drawback. This may be personal preference, but I find it easier to reason over a set of structs that represent what was extracted from the
I would very much like to give users of this library and users of I'm not sold on the idea that abandoning I view |
Makes sense; I appreciate the counterpoints. |
This PR reimplements parsing using Syn's attribute parsing library, which lifts a few limitations previously imposed on derive_builder's implementation by
darling
.Keywords in attributes:
darling
doesn't make it possible to use keywords in a nested attribute, such asfield(type = "...")
. I have added back support for that syntax in this PR (but also keptfield(ty = "...")
as an alias for the same thing for backward compatibility).Attributes containing keywords can't be parsed with 0.20 TedDriggs/darling#238
Factoring commonality from different data structures: for this PR I have not gone overboard with refactoring, but I did move the trio of
public
+private
+vis = "..."
to a single central place, as it was repeated across 5 different structs. This PR unlocks additional possibilities for factoring out common behavior, and there are pre-existing comments to the effect that this would be desirable.Add support for
flatten
TedDriggs/darling#146Validation during parse: with
darling
, structs are created in a potentially invalid state and then code needs to crawl them after the fact to perform validation. In this PR, structs do not get constructed in an invalid state; validation is integrated with the parsing. This also means various "DO NOT USE" fields go away in this PR.Passing state from outer contexts to inner: derive_builder has workarounds that exist because
darling
's FromMeta needs to be able to fully construct the output with no context other than the input Meta. In this PR, parsing is handled top to bottom by free-form function calls; additional arguments can be passed through as it becomes useful. For example, one can parse attributes at the struct level and then pass data from those to the code that parses attributes at the field level.Compile time: this PR improves compile time of derive_builder by 35% on my machine (5.9 seconds to 3.8 seconds).