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

Support shared #[builder] configuration in #[bon] macro at the impl block level #144

Open
Veetaha opened this issue Sep 18, 2024 · 0 comments
Labels
feature request A new feature is requested

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Sep 18, 2024

In some cases, developers would like to share the #[builder(...)] configuration across all their methods in the impl block, or even across all impl blocks.

Today, the users of bon need to copy-paste the same builder configs across all methods inside of the impl block manually, which isn't convenient when the number of methods is big and growing.

The proposed syntax is the following:

#[bon(builder(on(...), finish_fn = ..., derive(...))]
impl Foo {
    #[builder] // will inherit configs from `#[bon(builder(...))]`
    fn method(/**/) { /**/ }
    
    // Won't have a `#[builder]` generated
    fn regular_method(/**/) { /**/ }
}

This way the developers can move their configs to the top of the impl block to prevent code duplication at the entire impl block level. If the developers want to share these configs between multiple impl blocks they can easily create an attribute alias with macro_rules_attribute::attribute_alias.

Once we have this feature, the documentation for the "Shared Configuration" pattern needs to be updated to propose a solution for sharing configs for associated methods using the new syntax.

A note for the community from the maintainers

Please vote on this issue by adding a 👍 reaction to help the maintainers with prioritizing it. You may add a comment describing your real use case related to this issue for us to better understand the problem domain.

@Veetaha Veetaha added the feature request A new feature is requested label Sep 18, 2024
@Veetaha Veetaha changed the title Add support for shared #[builder] configuration to #[bon] macro at the impl block level Support shared #[builder] configuration in #[bon] macro at the impl block level Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new feature is requested
Projects
None yet
Development

No branches or pull requests

1 participant