Skip to content
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

More fine-grained field visibility #246

Closed
indietyp opened this issue Apr 6, 2022 · 2 comments
Closed

More fine-grained field visibility #246

indietyp opened this issue Apr 6, 2022 · 2 comments

Comments

@indietyp
Copy link

indietyp commented Apr 6, 2022

Hello, first off: great project!

I am currently trying to integrate the builder with my tests, and therefore I'd need the fields exposed. After looking through the code, there seems to be #[builder(field(public))] to switch the field to pub, but not to pub(crate) or pub(super).

Is there another way to set the visibility, or is this currently the only way to do things?
I'd love a struct level [builder(field(vis = "pub(super)"))] or something similar. Even at a field level, this would be very helpful.

@indietyp
Copy link
Author

indietyp commented Apr 6, 2022

I'd be willing to implement such a (backward-compatible) change and create a pull request if that is desired.

@TedDriggs
Copy link
Collaborator

TedDriggs commented Apr 6, 2022

A pull request would be great, thanks for offering to take that on.

Here's a breakdown of steps I'd suggest:

  1. Update the darling dependency to 0.13.4 so you pick up the impl FromMeta for syn::Visibility, since that'll make your life much easier.
  2. Update the derive_builder::macro_options::darling_opts::FlagVisibility trait to add a third required method, fn explicit(&self) -> Option<&Visibility>;. Note that doing this will slightly increase the scope of your PR beyond this issue, as you'll end up adding this option for all the places that have visibility controls in derive_builder.
  3. Update the FlagVisibility::as_expressed_vis method to consider explicit. This can't be set when public or private is present.
  4. Rename FlagVisibility to Visibility since it's no longer just about flags. This does mean you'll need to refer to syn::Visibility explicitly rather than adding use syn::Visibility, so you may want to avoid a use statement above.
  5. Add some compile-fail tests that show how combining these properties on a single field, setter, etc. will cause a good compile error.
  6. Add some compile-fail tests that validate visibility propagates correctly for structs, build functions, setters, and fields.
  7. Update lib.rs documentation

Steps 1-5 are done in #247; so documentation and tests are all that remain.

TedDriggs added a commit that referenced this issue Apr 19, 2022
Fields, setters, build methods, and builder structs can now be marked
as public, private, or have a restricted visibility with vis = "...".

Fixes #246
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants