rust-typed-builder icon indicating copy to clipboard operation
rust-typed-builder copied to clipboard

`setter(transform)` requires the type to be public

Open Pauan opened this issue 4 months ago • 0 comments

Minimal example reproducing the error:

mod foo {
    use typed_builder::TypedBuilder;

    struct Bar;

    #[derive(TypedBuilder)]
    pub struct Foo {
        #[builder(setter(transform = |x: u32| Bar))]
        foo: Bar,
    }
}

use foo::Foo;

fn main() {
    Foo::builder()
        .foo(5)
        .build();
}

That gives the following undesired error:

error: type `Bar` is private
   --> src/lib.rs:18:10
    |
18  |         .build();
    |          ^^^^^ private type

The foo method accepts a u32, not a Bar, so the Bar type shouldn't be exposed, so there shouldn't be any error.

But there is an error. This makes it impossible to use private types with transform.

Pauan avatar Jun 21 '25 20:06 Pauan