builder-pattern icon indicating copy to clipboard operation
builder-pattern copied to clipboard

Allow adding independent values to a Vec/HashMap etc.

Open WhiteHatTux opened this issue 2 years ago • 1 comments

Given a struct like this:

#[derive(Debug, Builder)]
pub struct QueryParameters {
    pub table_name: String,
    #[default(Option::None)]
    pub index_name: Option<String>,
    #[default(Option::None)]
    pub key_condition_expression: Option<String>,
    pub expression_attribute_values: Vec<(String, AttributeValue)>,
}

I would like to generate like this:

QueryParameters::new()
.table_name("table")
.add_expression_attribute_values(("string".to_string(), AttributeValue::S("attribute")))
.add_expression_attribute_values(("secondString".to_string(), AttributeValue::S("second attribute")))
.build();

So when calling "new" the expression_attribute_values are initialized, and then I can call the builder method however many times I want and it will add to the existing Vec.

The same could also be applied to HashMap and other iterables. Similar to what lombok provides for java devs: https://projectlombok.org/features/Builder#singular

I checked the documentation but couldn't find a way to do this with the current version of the library.

WhiteHatTux avatar Feb 18 '23 02:02 WhiteHatTux

Thanks for making the issue! I'll work on it soon.

SeokminHong avatar Feb 21 '23 10:02 SeokminHong