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 derive support #69

Closed
BrynCooke opened this issue Jul 31, 2022 · 1 comment · Fixed by #72
Closed

Add derive support #69

BrynCooke opened this issue Jul 31, 2022 · 1 comment · Fixed by #72

Comments

@BrynCooke
Copy link
Owner

Often you just want a builder for a struct without wanting to create a constructor.

This is a natural progression for the code:

  1. Struct with builder
  2. Struct starts needing bespoke handling for construction.
  3. Use constructor with builder.

Idea is that a derive macro could be introduced that allows derivation of a new method and builder.

@BrynCooke BrynCooke linked a pull request Jul 31, 2022 that will close this issue
@BrynCooke BrynCooke changed the title Allow builder on structs Add derive support Jul 31, 2022
@BrynCooke
Copy link
Owner Author

#[derive(buildstructor::Builder)]
pub struct MyStruct {
    simple: usize,
}

This will derive the following:

#[buildstructor::buildstructor]
pub impl MyStruct {
    #[builder(visibility="pub")]
    fn new(simple: usize)->MyStruct {
        Self {
          simple
        }
    }
}

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.

1 participant