apache / iceberg-rust

Apache Iceberg
https://rust.iceberg.apache.org/
Apache License 2.0
673 stars 159 forks source link

Add `fallback` attribute to all `strip_option`s. #708

Open ryzhyk opened 11 hours ago

ryzhyk commented 11 hours ago

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.