Introduce bool shorthand (`#[builder(flag)]`)
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- rust
- Domain
- developer-experience
Research direction
The issue names no files or tests. Start by locating the Builder derive macro's handling of boolean fields and review existing setter-generation tests; completion means supporting the proposed true and false shorthand while preserving ordinary boolean setters.
Written by the indexing model from the issue text.
Description
Hey there,
Bon is great but it still feels weird to write .property(true) for booleans and I feel that an option to shorten this usage would be a nice addition.
The syntax is just an example of how I would see it implemented :
use bon::Builder;
#[derive(Builder)]
struct User {
id: u32,
#[builder(bool)] // add some attribute to a boolean property
color: bool,
}
And then use it without specifying true :
let user = User::builder()
.id(1)
.color() // true
.build();
For falsy values, one could think of adding the same method with a prefix (no_ by default) :
use bon::Builder;
#[derive(Builder)]
struct User {
id: u32,
#[builder(bool, false = "no")] // optional, defaults to "no"
color: bool,
}
And then :
let user = User::builder()
.id(1)
.no_color() // false
.build();
let user = User::builder()
.id(1)
.color() // still valid : true
.build();
Feedback is welcome, it would greatly improve my builders!
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