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 Future Transformation for FluentBuilders #1027

Open
2 tasks done
jinyoung-cs opened this issue Dec 28, 2023 · 0 comments
Open
2 tasks done

Support Future Transformation for FluentBuilders #1027

jinyoung-cs opened this issue Dec 28, 2023 · 0 comments
Labels
feature-request A feature should be added or improved. p3 This is a minor priority issue

Comments

@jinyoung-cs
Copy link

Describe the feature

aws-sdk-rust's codegen produces FluentBuilders which provide future-like builders which must be send() off in order to be awaited. Arguably the send itself is boilerplate since the builder can be treated like a future. I am proposing to implement IntoFuture for all builders.

Use Case

Remove boiler plate.

Proposed Solution

According to rust docs: https://doc.rust-lang.org/std/future/trait.IntoFuture.html

The .await keyword desugars into a call to IntoFuture::into_future first before polling the future to completion. IntoFuture is implemented for all T: Future which means the into_future method will be available on all futures.

Therefore this is the proposed solution

impl IntoFuture for FooFluentBuilder {
    type Output = Result<FooOutput, SdkError<FooError, HttpResponse>>;
    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output>>>;

    fn into_future(self) -> Self::IntoFuture {
        Box::pin(self.send())
    }
}

Key notes: This has somewhat a trivial performance consequence as this is making a heap alloc for the future along side a dynamic network call. If such a penalty is not acceptable, then send may still be used as an alternative. If the sdk team would not like to introduce a disparity between the two calls then RFC 2515, "Permit impl Trait in type aliases" is required before implementation.

Proposed implementation would be the implementation linked directly above, and reimplementing with RFC 2515 when stabilized. Since the current implementation returns an opaque future, introduction of RFC 2515 shouldn't be a breaking change.

Other Information

This maintains backwards compatibility and allows eventual deprecation of send if such a breaking change is desired, and also allows new usage of immediately awaiting the builder.

Acknowledgements

  • I may be able to implement this feature request
  • 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
@jinyoung-cs jinyoung-cs added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 28, 2023
@jmklix jmklix added p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

2 participants