feat: support the default switch in the on(...) clause - #398
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for a boolean default switch inside #[builder(on(...))], enabling blanket application of #[builder(default)] to matching required members (without affecting Option<T> members or members that already have a member-level default).
Changes:
- Extend
OnConfigparsing to recognizedefaultas a supportedon(...)flag. - Apply
on(type_pattern, default)during member config merging to mark matching required members as#[builder(default)]. - Add integration tests and update the website reference docs with the new
defaultusage and limitations.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| website/src/reference/builder/top-level/on.md | Documents default as a supported on(...) flag and adds an example + clarifies boolean-only limitation. |
| bon/tests/integration/builder/attr_on.rs | Adds coverage for blanket-default matching (path + generic) and interaction with into and member-level defaults. |
| bon-macros/src/builder/builder_gen/top_level_config/on.rs | Extends on(...) meta parsing to accept the default flag. |
| bon-macros/src/builder/builder_gen/member/named.rs | Implements merging logic to apply on(..., default) to matching required members while leaving optional/defaulted members untouched. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Collaborator
|
Thanks for the PR, I'll release it soon |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #366.
This adds
defaultas a switch in theon(...)clause, so you can write#[builder(on(Vec<_>, default))]to make every matching required member optional and fall back to itsDefaultvalue. It's the boolean form from your comment on the issue, so a customdefault = ...value is still left to #152.Members that already have a
#[builder(default = ...)]or areOption<T>are left untouched, so this doesn't change anything for existing builders. I wired it into the same type-pattern matching thatintoandoverwritableuse, added tests toattr_on.rs, and documented the attribute on theonreference page.