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
Read this if you found this issue because you want to have builder syntax for methods in traits
The design for this feature is rather hard and is yet to be researched, but bon should eventually be there! If you'd like to benefit from the builder syntax in your traits (e.g. assign default values, allow the caller to skip optional parameters, etc.), in the meantime I recommend you to just define a separate "parameters" struct annotated with a #[derive(bon::Builder)].
Example:
#[derive(bon::Builder)]structPutStarParams{#[builder(into)]github_repo:String,// .. other params}traitGithubClient{fnput_star(params:&PutStarParams) -> Result;}implGithubClientforMyClient{fnput_star(params:&PutStarParams) -> Result{/**/}}let client = MyClient::new();// Use builder syntax to construct the params struct:let params = PutStarParams::builder().github_repo("elastio/bon").build();// call the trait method:
client.put_star(params)?;
A note for the community from the maintainers
Please vote on this issue by adding a 👍 reaction to help the maintainers with prioritizing it. You may add a comment describing your real use case related to this issue for us to better understand the problem domain. Sharing your use case will help with moving this issue forward!
Main issue body
We need some syntax to allow developers to generate builders from traits and trait impl blocks. This way it should be possible to define a trait that uses builder syntax for its methods.
The main problem here is that trait declarations and trait impl blocks are syntactically separated. We can also have multiple impl blocks. It would be awesome if all the impl blocks didn't have to redeclare the trait methods' parameter lists. The macro should probably generate a struct with input parameters that is then passed into the trait methods.
This all has a bunch of nuances (e.g. support for dyn Trait objects, methods without self). This feature requires a huge design effort.
The text was updated successfully, but these errors were encountered:
Read this if you found this issue because you want to have builder syntax for methods in traits
The design for this feature is rather hard and is yet to be researched, but
bon
should eventually be there! If you'd like to benefit from the builder syntax in your traits (e.g. assign default values, allow the caller to skip optional parameters, etc.), in the meantime I recommend you to just define a separate "parameters" struct annotated with a#[derive(bon::Builder)]
.Example:
A note for the community from the maintainers
Please vote on this issue by adding a 👍 reaction to help the maintainers with prioritizing it. You may add a comment describing your real use case related to this issue for us to better understand the problem domain. Sharing your use case will help with moving this issue forward!
Main issue body
We need some syntax to allow developers to generate builders from traits and trait impl blocks. This way it should be possible to define a trait that uses builder syntax for its methods.
The main problem here is that trait declarations and trait impl blocks are syntactically separated. We can also have multiple impl blocks. It would be awesome if all the impl blocks didn't have to redeclare the trait methods' parameter lists. The macro should probably generate a struct with input parameters that is then passed into the trait methods.
This all has a bunch of nuances (e.g. support for
dyn Trait
objects, methods withoutself
). This feature requires a huge design effort.The text was updated successfully, but these errors were encountered: