-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support setting doc & attribute for each field separately #6
base: main
Are you sure you want to change the base?
Conversation
- Tests are yet to be written
I've also added documentation append mode for good measure. So now you can do this: /// 69
#[optfield(Opt, doc = append("420"))]
struct Foo {
/// nice
#[optfield_field(doc = append("nicer"))]
foo: String,
} this generates #[doc = " 69"]
#[doc = "420"]
struct Opt {
#[doc = " nice"]
#[doc = "nicer"]
foo: Option<String>,
} |
Thank you for the PR. I encourage you in the future to first open a feature request issue before putting in work for a PR. Although tested, it is not documented (maybe it should) that However, I will take a closer look and give this some thought in the near future. I hope this doesn't come across as a lack of appreciation for your effort. I recommend that any further work on this PR be postponed until I come to a conclusion regarding whether we should pursue this further. There is a real possibility that this will not be merged, so I think it's best to avoid doing more work before it is decided to add this to |
- Not yet stabalised in Rust 1.56.0
Thanks for a quick reply, and please do take your time to think about whether this feature is a good inclusion or not. I completely understand your concerns on future maintainability. Personally I hate janky code in general for the same reasons, hence why I'm here coding in Rust. While I cannot say that I have foreseen every possible pitfall, I can assure you that I've tried my best to keep things extensible, and that I did not make any unidiomatic/haphazard design decisions. So for example, the allowed arguments on the fields have a distinct container type, so that we can trivially restrict what field arguments are allowed (at the cost of having some code duplication, but that's easily solvable with a trait if necessary). Also here I completely refactored this trait because the logic in I opted to make the trait much simpler and put most of the attribute generation logic into each In terms of the specific logic, everything I have now is just a simple per-field override. So for example if both the struct Hopefully this can help reassure you that I haven't sacrificed too much maintainability to implement this feature. And I do intend to add documentation and full test coverage too. And finally, thanks for giving me a heads-up on the possibility that this will not be merged. That's not a problem with me and I fully respect your decision. However I'll still go ahead and finish the tests and documentation on my branch, just to tie up loose ends. Please don't misinterpret this as me trying to pressure you; it's just that I personally need this feature for my project, and I'd rather it has proper tests and documentation than not. So yeah, since I'm doing this for myself anyway, might as well offer to upstream the feature. Again, I fully respect your choice in this matter; if necessary, I'm okay with having a git dependency that pulls directly from my branch indefinitely. |
- common traits used for debugging are no longer conditionally derived
An update (and note to future self): It seems like some extra work is required for now, because There is an available workaround that involves "consuming" the field attributes (i.e. use it then remove it), but as you mentioned, it gets a little tricky when |
The workaround has been implemented, with surprisingly few changes I must say. As is the case previously, this is intended to work fine with multiple I still have tests to add, but you can already try it out right now. I've had to use a different attribute name for the field attribute ( |
Summary
Basically, this PR would allow you to do this:
... which generates
Checklist