Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Silvea12 opened this issue Apr 10, 2023 · 1 comment

Comments

@Silvea12
Copy link

Silvea12 commented Apr 10, 2023

When trying to create a builder that takes a Vec as the builder and builds into a HashMap, incorrect code seems to be generated if you try to generate a collection setter.

What happens is that add_buggy expects get_or_insert_with to exist on the Vec that is created for the builder, but it does not, so it fails.

A minimal reproduction case:

#[derive(Builder)]
struct MyBuggyBuilder {
    #[builder(
        field(
            type = "Vec<i32>",
            build = "self.buggy.into_iter().map(|e| (e,e)).collect()"
        ),
        setter(each(name = "add_buggy", into))
    )]
    pub buggy: HashMap<i32, i32>,
}
@TedDriggs
Copy link
Collaborator

The issue appears to be coming from these lines. It looks like this initialization code will need to take the field type into account.

I'm happy to review a PR for this, but implementing it myself isn't something I have time for.

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

No branches or pull requests

2 participants