colin-kiegel / rust-derive-builder

derive builder implementation for rust structs
https://colin-kiegel.github.io/rust-derive-builder/
Apache License 2.0
1.28k stars 82 forks source link

Enhance support for collection types #260

Closed sunng87 closed 2 years ago

sunng87 commented 2 years ago

A further step for supporting collection types like Vec or HashMap is to generate insertion function for its content types. This allows user to create collection in a declarative manner.

For Example:

#[derive(Builder)]
pub struct Group {
  members: Vec<User>
}

Generated builder contains a function called push_member, by which you can

builder.
  .push_member(user1)
  .push_member(user2)
TedDriggs commented 2 years ago

Have you looked at the each setter options?

sunng87 commented 2 years ago

Cool. That seems to be my need. I'll do some experiment with it and come back to you later.

sunng87 commented 2 years ago

It works! Thank you for your response.

DontBreakAlex commented 1 month ago

I'm sorry to dig up this issue, but has this feature been removed ? I can't find any mention of each in the docs and this doesn't build:

error: Unexpected meta-item format `word`
  --> src/parse.rs:17:22
   |
17 |     #[builder(setter(each))]
   |                      ^^^^
TedDriggs commented 1 month ago

Still exists, it just doesn't support that format - that's why the error says "unexpected format" and not "unknown field"

Usage is here