Closed SteadBytes closed 2 years ago
Combining setter(strip_option and setter(each) to provide an "append" API for an optional field fails to compile:
setter(strip_option
setter(each)
error[E0599]: no method named `extend` found for mutable reference `&mut Option<Vec<i32>>` in the current scope
Provide a builder method FooBuilder.bar for appending to FooBuilder.bars one item at a time whilst defaulting to None if never called.
FooBuilder.bar
FooBuilder.bars
None
#[macro_use] extern crate derive_builder; #[derive(Debug, PartialEq, Default, Builder)] struct Foo { #[builder(default, setter(strip_option, each = "bar"))] bars: Option<Vec<i32>>, } fn main() { assert_eq!( FooBuilder::default().build().unwrap(), Foo { bars: None }, "None if unset" ); assert_eq!( FooBuilder::default().bar(1).bar(2).bar(3).build.unwrap(), Foo {[] bars: Some(vec![1, 2, 3]) }, "Some(Vec<i32>) when set" ); }
Apologies if I'm missing something to make this work. Otherwise, I think this would be a useful feature to support if possible.
Combining
setter(strip_option
andsetter(each)
to provide an "append" API for an optional field fails to compile:Example
Provide a builder method
FooBuilder.bar
for appending toFooBuilder.bars
one item at a time whilst defaulting toNone
if never called.Apologies if I'm missing something to make this work. Otherwise, I think this would be a useful feature to support if possible.