Replace FluentBuilders with FluentTypedFuture #1086
Labels
feature-request
A feature should be added or improved.
needs-triage
This issue or PR still needs to be triaged.
Describe the feature
FluentBuilders are a mechanism used to construct requests prior to being sent. FluentBuilders have two downfalls:
ConstructionFailure
send
which is basically just boilerplate.Use Case
Replacing FluentBuilders with compile-time type checks guarentee that required fields are fulfill upon request. We can await these FluentTypedFutures directly instead of using
send
. It is basically user ergonomics and safety.Proposed Solution
I'll use
aws_sdk_s3::Client::create_bucket
for example. If the create-bucket operation does not havebucket
set, construction will fail at runtime.There is a popular alternative to fallible builder pattern called typed builders (See: https://crates.io/crates/typed-builder). We can remove an entire class of runtime errors with such a pattern.
Create bucket builder may look something like this:
playground
Other Information
There are no major issues with the
future
aspect of this change. It can be implemented today for existing builder types with backwards and forward compatibility.There are three major issues with the
typed
aspect of this change:ConstructionFailures
in tests, though those tests could be removed entirely.self
as opposed to&mut self
, FluentTypedFuture would be more difficult to use in branching code. This is particularly true in branching code with multiple required fields e.g.aws_sdk_s3::Client::copy_object
(bucket
,copy_source
, andkey
are required)The counterargument to this point is that these are owned builder patterns, and the fields should be prepared beforehand. This is generally true in practice as well, but nevertheless, it is a breaking behavioral change.
copy_object
for example could have 23 = 8 builders. (Sum of every combination of required fields is the sum of binomial coefficients, i.e. Pascal's Triangle = 2required fields). This is the pathological case.n
wheren
represents the number of required fields.Invalid
misguiding users.It's hard to say how much this would impact binary and compile times, but thought it worth mentioning.
Acknowledgements
A note for the community
Community Note
The text was updated successfully, but these errors were encountered: