feat: support partial_attr for struct fields - #44
Conversation
10da986 to
aa10700
Compare
aa10700 to
843ba9e
Compare
843ba9e to
bf7583b
Compare
partial_attr for struct fields
bf7583b to
46e661e
Compare
LukasKalbertodt
left a comment
There was a problem hiding this comment.
Thanks for the PR, this is a pretty obvious missing feature in confique and your idea to use it for clap is also good! (Will answer that thread separately).
I just have a bunch of small comments.
|
I had some thoughts about I dislike how it looks:
So how could one improve this? Using
With (1) I don't like the need for quotes, as it destroys syntax highlighting for the attribute. For (2) und (3), the derive macro would need to reserve another derive macro helper attribute and sth like Do you have any thoughts on this? Do you agree with the problems I see with the current solution? Do you think any of the proposed solutions is an improvement? Which is best then? Any other ideas? |
Sure, happy to provide some thoughts here. I do agree that the current level of nesting is a bit excessive. 1-3 - I agree that reserving another attribute name wouldn't be ideal. I think most proc macros tend to stick to a single attribute helper (for struct level attributes, at least), so it's easier to remember. 5-7 - introduces some syntax that looks a bit unconventional to me. I think that might be confusing for some users. 8 - I agree doesn't solve the nesting problem, so that's not ideal. That leaves 4, which I think is a good option. Using |
84894c1 to
dd1d3c9
Compare
e4a442b to
12d551c
Compare
12d551c to
19aebf9
Compare
|
Thanks a bunch and sorry for the delay! Code looks nice. I just removed the last commit (the CI change) since I already fixed that in Regarding the change to Regarding the general clap story: as you said, with this PR, a big blocker is solved. I want to dig into the issue myself again soon and figure out what's already possible and if it's maybe already enough. Same goes for the |
|
I did release this PR now as 0.3.1 with a bunch of smaller things. It doesn't fully support your use case yet (due to the Another aside: I am considering renaming |
|
Thanks for getting this merged!
"Layer" makes sense to me, especially since "layered configuration" is a pretty standard term these days. I've seen some libraries treat partials and layers as two distinct concepts ( |
|
For the protocol: I renamed "partial" to "layer" now but did not change the syntax of the attribute. None of the options were really all that nice. The rename already solved my main problem (the weird way my brain read it). Only remaining problem is the two-additional layers of nesting. But oh well 🤷 |
Related to #19
This adds support for the existing derive attribute
partial_attrin struct fields. This is useful if you need to derive something on the generated partial struct that requires specifying attributes on struct fields. Being able to derive clap's traits on the partial structs is the main motivation for this, but it also works for any other trait (derive_more is the example I chose for the test).This is most of the work required to support using partial structs with clap. More info in this comment: #19 (comment)