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

Support generating builders from traits and trait impls #123

Open
Veetaha opened this issue Sep 10, 2024 · 2 comments
Open

Support generating builders from traits and trait impls #123

Veetaha opened this issue Sep 10, 2024 · 2 comments
Labels
design needed The feature requires more design effort feature request A new feature is requested

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Sep 10, 2024

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.

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.

@Veetaha Veetaha added design needed The feature requires more design effort feature request A new feature is requested labels Sep 10, 2024
@dzmitry-lahoda
Copy link
Contributor

assuming it is possible to do, when it is useful?

@Veetaha
Copy link
Contributor Author

Veetaha commented Sep 11, 2024

As an example, the current Hashicorp Vault API uses functions with lots of positional parameters and it always accepts an impl Client.

If only we had a way to generate builder syntax for that Client trait, that would make it possible for vaultrs to use the syntax like this:

let client: impl Client = /**/

client
    .create_certificate()
    .mount("...")
    .cert_name("...")
    .aws_public_cert("...")
    .send()
    .await?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design needed The feature requires more design effort feature request A new feature is requested
Projects
None yet
Development

No branches or pull requests

2 participants