rust-derive-builder icon indicating copy to clipboard operation
rust-derive-builder copied to clipboard

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

Open Silvea12 opened this issue 1 year ago • 1 comments

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>,
}

Silvea12 avatar Apr 10 '23 22:04 Silvea12