Skip to content

feat: support the default switch in the on(...) clause - #398

Merged
Veetaha merged 1 commit into
elastio:masterfrom
ChrisJr404:feat/on-default
Aug 24, 2026
Merged

feat: support the default switch in the on(...) clause#398
Veetaha merged 1 commit into
elastio:masterfrom
ChrisJr404:feat/on-default

Conversation

@ChrisJr404

Copy link
Copy Markdown
Contributor

Closes #366.

This adds default as a switch in the on(...) clause, so you can write #[builder(on(Vec<_>, default))] to make every matching required member optional and fall back to its Default value. It's the boolean form from your comment on the issue, so a custom default = ... value is still left to #152.

Members that already have a #[builder(default = ...)] or are Option<T> are left untouched, so this doesn't change anything for existing builders. I wired it into the same type-pattern matching that into and overwritable use, added tests to attr_on.rs, and documented the attribute on the on reference page.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 OnConfig parsing to recognize default as a supported on(...) 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 default usage 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.

@Veetaha

Veetaha commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR, I'll release it soon

@Veetaha
Veetaha merged commit 83845f6 into elastio:master Aug 24, 2026
29 of 36 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants