You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Option specific builder attributes set on the type don't have to be stripped out (modifying the example from the docs)
use typed_builder::TypedBuilder;#[derive(TypedBuilder)]#[builder(field_defaults(default, setter(strip_option)))]structFoo{// Defaults to None, options-stripping is performed:x:Option<i32>,// Don't need to set `!strip_option` because it isn't an option field to begin with// #[builder(setter(!strip_option))]y:i32,// Defaults to Some(13), option-stripping is performed:#[builder(default = Some(13))]z:Option<i32>,// Accepts params `(x: f32, y: f32)`// Similarly, the `!strip_option` attribute is removed#[builder(setter(transform = |x: f32, y: f32| Point{ x, y }))]w:Point,}#[derive(Default)]structPoint{x:f32,y:f32}
The text was updated successfully, but these errors were encountered:
Option<T> specific setter attributes only get applied to Option<T> fields, removing the need for explicit negation on non-option fields.
#[builder(explicit_option)] might then be useful, but my first reaction is "If I need to explicitly set something to None, then there is probably real application-logic meaning behind that choice that would be better as a named enum variant."
Reason
Option
semantics in rust are naturally "optional", and ideally wouldn't have to set them on the builder.strip_default
on non-optional fieldsDesired behavior
field_attributes(default)
would fail here becauseWrapper
has no default.Option
specific builder attributes set on the type don't have to be stripped out (modifying the example from the docs)The text was updated successfully, but these errors were encountered: