Support prefix overrides at the top level with `#[builder(on(...))]`
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start by reading the existing handling for #[builder(on(...))] and the code that chooses prefixes for Option setters. Use a minimal Foo example with value and label fields to compare the current maybe_ names with the requested configurable set_ names; done means the type-level override is defined and its generated setter names are verified.
Written by the indexing model from the issue text.
Description
Hi there,
First off, thank you for creating and maintaining Bon—it’s been a pleasure working with it!
As I migrate a codebase to Bon, I’ve run into a challenge with the naming conventions for setters handling Option fields. My current codebase uses set_ as the prefix for these setters. While Bon's built-in support for Option setters is a fantastic feature that removes the need for manual definitions, it uses the maybe_ prefix by default.
This mismatch means I still have to manually rename every setter to match my convention, which undermines some of the convenience.
I’d like to suggest two potential improvements to make this process smoother for me and other users:
- Set
set_as the default prefix forOptionsetters (this align with naming in #142) - Introduce configurability for setter prefixes at the type level:
Allowing users to define their preferred prefix (e.g.,set_,maybe_, or custom ones) would offer greater flexibility and make Bon more adaptable to different codebases and conventions.
While either of the suggested changes would address my use case, I believe adding the ability to configure this at the type level would provide greater flexibility and cover a wider range of use cases.
Code snippet:
#[derive(Builder)]
#[builder(on(optional, prefix = "set_"))] // Example syntax for explanation, not necessarily the suggested approach
struct Foo {
value: Option<String>,
label: Option<String>,
}
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.
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 46
- Avg merge
- 53m
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from elastio/bon
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
feature request
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
feature request
Difficulty 5/5 Over a week Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gitbutlerapp/gitbutler#15998 · 1 comment ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100