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

Handle deprecated fields #76

Closed
mauricelam opened this issue Mar 3, 2023 · 2 comments · Fixed by #88
Closed

Handle deprecated fields #76

mauricelam opened this issue Mar 3, 2023 · 2 comments · Fixed by #88

Comments

@mauricelam
Copy link

mauricelam commented Mar 3, 2023

If I have a deprecated field in my struct, the generated TypedBuilder has two unexpected behavior:

  1. It complains about the used of deprecated fields in the definition, but adding #[allow(deprecated)] on the struct doesn't help (because it's used in a separate, generated block?)
  2. The generated setter is not marked as deprecated, so users of the builder won't know that they are setting a deprecated field.

Example:

#[allow(deprecated)]
#[derive(Debug, TypedBuilder)]
pub struct StringConfig {
    #[deprecated(note="Do not use.")]
    #[builder(default = true)]
    pub save: bool,
}
@mo8it
Copy link
Contributor

mo8it commented Jun 4, 2023

That should be easy. We need to add #[allow(deprecated)] to the last line of build() where in this example StringConfig { save }.into() is called.

Why is there an .into() btw?

Then we need to add the same deprecation note of the field save to the method save.

Do we want to throw a compilation error if the default attribute is not set?

@idanarye Can I give it a try for a PR?

@idanarye
Copy link
Owner

idanarye commented Jun 4, 2023

@mo8it Go for it.

The into, BTW, is because of #80. It did cause a problem for #84, so I'll have to make it conditional on whether or not #[builder(build_method(into))] is used, but there are other things blocking #84 so I leave it in its branch for now.

@mo8it mo8it mentioned this issue Jun 5, 2023
mo8it pushed a commit to mo8it/rust-typed-builder that referenced this issue Jun 11, 2023
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 a pull request may close this issue.

3 participants