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

Commits on Nov 21, 2024

  1. Add fallback attribute to all strip_options.

    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 <[email protected]>
    Leonid Ryzhyk committed Nov 21, 2024
    Configuration menu
    Copy the full SHA
    4e5e39e View commit details
    Browse the repository at this point in the history