derive_builder is a proc-macro that creates builders for structs. v0.10.0-alpha is now available, with one very major change and a couple minor ones.
FooBuilder::build now returns
Result<Foo, FooBuilderError> instead of
Result<Foo, String>. The default
FooBuilderError is a generated enum with variants for missing fields and custom errors.
This change enables code to programmatically handle missing fields, and avoids needing to allocate for the most common failure mode of the
build method. We believe the vast majority of callers use
build().unwrap(), so they should be source compatible with the new version.
Default constraint from type parameters
Given a struct
Foo<T>, the derived builder would require
T: Default for
FooBuilder, but that wasn't necessary. This shouldn't break any already-working code, barring a weird edge case.
Error for Invalid Attributes
#[builder(default = my::path)] and other malformed attributes would have been silently ignored. This probably wouldn't have produced the desired effect, but it also wouldn't have produced a compile error. Now that will be marked as an invalid attribute.
If you use
derive_builder in your crate, please try updating to
0.10.0-alpha and let us know if you hit problems (or if the new changes make your life better somehow!)