awslabs / awslabs/aws-sdk-rust

Support Future Transformation for FluentBuilders

Open
#1,027 0 comments 0 reactions 0 assignees View on GitHub
feature-request p3
Dominant language
Rust
Stars
3.3k
Forks
290
Avg merge
1d 12h
Merged PRs (30d)
3

Description

### 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

``` rust
impl IntoFuture for FooFluentBuilder {
type Output = Result>;
type IntoFuture = Pin>>;

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"](https://github.com/rust-lang/rust/issues/63063) 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

- [X] 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](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) 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

Contributor guide

Open the contributing guide

Research direction

Start by locating the codegen path that produces FluentBuilders and inspect how each builder's send() future is represented. Evaluate the proposed IntoFuture implementation across generated builders, including its allocation and compatibility implications. Done means the generated builders can be awaited directly without breaking existing send() usage, with the relevant project checks passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, rust
Domain
backend-api-design, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.