Releases: BrynCooke/buildstructor
Releases · BrynCooke/buildstructor
0.2.0
#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]
- Annotate the impl with:
#[buildstructor::buildstructor]
- 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 aroundnew/*_new
are used.exit
=> The terminal method for the generated builder. Defaults tobuilder
for constructors andcall
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.