Skip to content

Releases: BrynCooke/buildstructor

0.2.0

10 May 21:08
Compare
Choose a tag to compare

#45
Major refactor to expand the scope of buildstructor.

To provide more control over generated builders and allow builders for methods with receivers the top level annotation has changed:

#[buildstructor::builder] => #[buildstructor::buildstructor]

  1. Annotate the impl with: #[buildstructor::buildstructor]
  2. Annotate methods to create a builders for with: #[builder]
#[buildstructor::buildstructor]
impl Foo {
    #[builder]
    fn new(simple: String) -> Foo {
        Self { simple }
    }
}

You can configure your builder using the #[builder] annotation, which has the following attributes:

  • entry => The entry point for your builder. If not specified then the pre-existing rules around new/*_new are used.
  • exit => The terminal method for the generated builder. Defaults to builder for constructors and call for methods.

In addition, you can now specify builders on methods that take self:

#[derive(Default)]
pub struct Client;

#[buildstructor::buildstructor]
impl Client {
    #[builder(entry = "phone", exit = "call")]
    fn phone_call(self, _simple: String) {}
}

fn main() {
    Client::default().phone().simple("3").call();
}

Note, if method parameters begin with _ then this is stripped for the builder method names.