Skip to content

Support collection setters on custom builder field types - #358

Open
ychampion wants to merge 1 commit into
colin-kiegel:masterfrom
ychampion:fix/collection-setter-custom-field
Open

ychampion wants to merge 1 commit into
colin-kiegel:masterfrom
ychampion:fix/collection-setter-custom-field

Conversation

@ychampion

Copy link
Copy Markdown

When #[builder(field(ty = "..."))] overrides a builder struct field's type (BuilderFieldType::Precise), the generated builder field is not wrapped in an outer Option<...>. Previously, Setter::to_tokens always emitted .get_or_insert_with(...) for setter(each = ...) (and two .get_or_insert_with(...) calls when combined with strip_option), assuming the builder field had an Option wrapper.

Match on (builder_field_is_option, stripped_option) when generating each setters so custom non-Option builder fields extend new.<field> directly, custom Option<Collection> fields with strip_option unwrap a single Option, and standard Optional builder fields keep their existing behavior.

Fixes #287

When `#[builder(field(ty = "..."))]` overrides a builder field's type,
the generated builder field is not wrapped in an outer `Option<...>`.
Update `Setter::to_tokens` to match on `(builder_field_is_option,
stripped_option)` when generating `each` setters so custom non-`Option`
builder fields extend `new.<field>` directly and custom `Option<...>`
fields with `strip_option` unwrap a single `Option`.

Fixes colin-kiegel#287

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using a collection setter with mismatched collections of Vec -> HashMap causes incorrect call to be made

1 participant