Split sync and async body into distinct types #262
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make the big split between synchronous responses and asynchronous responses, which offers ergonomic improvements and encourages users towards using the right methods by default as discussed in #202. This required the following changes:
Body
into two distinct types:AsyncBody
andBody
, which are asynchronous only and synchronous only, respectively.ResponseExt
into three traits:ResponseExt
for methods that don't use the body,ReadResponseExt
for synchronous methods that read from the body, andAsyncReadResponseExt
for async methods that read from the body. This offers some ergonomic improvements as well, as the async response methods can drop the_async
suffix, and Rust will automatically resolve to the correct method depending on whether the response is async or not.This split also enables a new capability that I did not think of before, which is that you can now use anything implementing
Read
as a request body such asFile
when using the synchronous API. For those not using async at all, this is a significant improvement!Fixes #202.