Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback attribute to all strip_options. #708

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ryzhyk
Copy link
Contributor

@ryzhyk ryzhyk commented Nov 21, 2024

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 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:

```rust
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.

Signed-off-by: Leonid Ryzhyk <leonid@feldera.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant