-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
feature requestA new feature is requestedA new feature is requested
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.
dsully, ferreira-tb, MuhannadAlrusayni, LeChatP and Chaoses-Ib
Metadata
Metadata
Assignees
Labels
feature requestA new feature is requestedA new feature is requested