Auto-derived TypedBuilder traits in combination with strip_option attributes are very hard to use in scenarios where options passed to the builder depend on user input. The problem is that this pattern doesn't work, since the two match branches return different types:
let builder = match x {
None => builder,
Some(x) => builder.x(x),
};
Fortunately typed_builder 0.20 supports an additional attribute (fallback) that generates a builder method that takes Option<T> in addition to the method that takes naked T.
With this attribute, we can write let builder = builder.x_opt(x).
This commit adds the fallback attribute to all fields that have the strip_option annotation.
Auto-derived
TypedBuilder
traits in combination withstrip_option
attributes are very hard to use in scenarios where options passed to the builder depend on user input. The problem is that this pattern doesn't work, since the two match branches return different types:Fortunately typed_builder 0.20 supports an additional attribute (
fallback
) that generates a builder method that takesOption<T>
in addition to the method that takes nakedT
.With this attribute, we can write
let builder = builder.x_opt(x)
.This commit adds the
fallback
attribute to all fields that have thestrip_option
annotation.