You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use the builder pattern mainly to emulate named arguments. But I don't want to have to call build.
What I must do currently
DoSomething::builder().foo(foo).bar(bar).build()// <- I want to remove this.run().await// the `into` attribute cannot handle opaque type such as `impl Future`, which was why calling `build` is the only way
What I hope for
DoSomething::builder().foo(foo).bar(bar).run()// this function captures DoSomethingBuilder by move.await
The text was updated successfully, but these errors were encountered:
You impl a constructor (new() is fronted by generated builder()), with the supported fields that you want to set.
Then during usage, when you're done call the build() (the "exit" method, which has been renamed to run) to indicate that you're done supplying mandatory params and that will then call the annotated new() method with those values.
In this example we create an instance of self with those method params in new() and call the structs .run() method on it which we can do since the builders own .run() is from the generated builder struct thus no conflict 👍
structMyStruct{foo:usize,bar:usize,}#[buildstructor::buildstructor]implMyStruct{#[builder(exit = "run")]asyncfnnew(foo:usize,bar:usize) -> bool{(Self{ foo, bar }).run()}fnrun(self) -> bool{self.foo == self.bar}}#[tokio::main]asyncfnmain(){let result = MyStruct::builder().foo(4).bar(2).run().await;assert_eq!(result, false);}
I use the builder pattern mainly to emulate named arguments. But I don't want to have to call
build
.What I must do currently
What I hope for
The text was updated successfully, but these errors were encountered: