aws-sdk-rust icon indicating copy to clipboard operation
aws-sdk-rust copied to clipboard

Support passing `model` builders directly as parameters

Open joshtriplett opened this issue 2 years ago • 2 comments

Describe the feature

Currently, calling a method that accepts a model struct requires first constructing the builder (ModelStruct::builder()), then calling methods on it, then calling .build() at the end. I'd love to leave off the .build() and have the method accepting the structure handle that, reducing boilerplate in the common case of constructing such a model struct and immediately passing it.

Use Case

Consider the following code:

        let reservation = self
            .ec2
            .run_instances()
            .launch_template(
                aws_sdk_ec2::model::LaunchTemplateSpecification::builder()
                    .launch_template_name(launch_template_name)
                    .build(),
            )
            .instance_type(instance_type.clone())
            /* ... */
            .send()
            .instrument(info_span!("RunInstances"))
            .await?;

If LaunchTemplateSpecification implemented From<Builder>, and launch_template accepted impl Into<LaunchTemplateSpecification>, that would allow leaving off the .build().

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [X] This feature might incur a breaking change

A note for the community

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue, please leave a comment

joshtriplett avatar Jul 06 '22 03:07 joshtriplett

I think this is an interesting proposal and I agree that less boilerplate is better. Thanks for submitting it.

Velfi avatar Jul 06 '22 15:07 Velfi

I'm running into this as well.. I find it very odd. Here is what I want to do:

  • Get a ECS Task Definition (using describe_task_definition),
  • Modify the returned TaskDefinition
  • Send the TaskDefinition to register_task_definition

But the SDK won't let me do that. I have to manually rebuild that TaskDefinition with builder functions. I expect I'll have the same problem as I make changes to ALB Rules as well..

I've encountered this all over the SDK where it seems to deliberately prevent me from working with the Structs it provides me to repurpose for another purpose.

If I have a fully formed *Input(eg Lambda's InvokeInput, or SSM's GetParameterInput) struct, why am I not allowed to send it directly to the API?

canadiannomad avatar Dec 03 '22 01:12 canadiannomad