idanarye / rust-typed-builder

Compile-time type-checked builder derive
https://crates.io/crates/typed-builder
Apache License 2.0
919 stars 52 forks source link

Apply field doc-comments to builder methods #146

Closed sunsided closed 4 months ago

sunsided commented 4 months ago

I noticed that the builder has support for explicitly provided comments, e.g. via

#[builder(
    default,
    setter(strip_option, doc = "Set `y`. If you don't specify a value it'll default to no value.",)
)]

However, regular doccomments would be ignored even when no setter-specific doc attribute is provided. With this PR, the following is now possible:

struct Foo {
    /// `x` value.
    ///
    /// This field is mandatory.
    x: i32,

    /// This doccomment is ignored for the setter. 
    #[builder(
        default,
        setter(strip_option, doc = "Set `y`. If you don't specify a value it'll default to no value.",)
    )]
    y: Option<i32>,

    #[builder(default = 20)]
    z: i32,
}

On the builder, x(...) will be documented with the regular doccomment, y(...) is documented with the setter attribute as before and z(...) remains undocumented, as before.

When the builder emits deprecated functions, they also inherit the documentation. This was not previously the case.

idanarye commented 4 months ago

Thanks!