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

Split sync and async body into distinct types #262

Merged
merged 7 commits into from
Nov 28, 2020
Merged

Conversation

sagebind
Copy link
Owner

@sagebind sagebind commented Nov 25, 2020

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:

  • Split Body into two distinct types: AsyncBody and Body, which are asynchronous only and synchronous only, respectively.
  • Split ResponseExt into three traits: ResponseExt for methods that don't use the body, ReadResponseExt for synchronous methods that read from the body, and AsyncReadResponseExt 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 as File when using the synchronous API. For those not using async at all, this is a significant improvement!

Fixes #202.

@codecov
Copy link

codecov bot commented Nov 25, 2020

Codecov Report

Merging #262 (936970e) into master (6a399a2) will increase coverage by 0.69%.
The diff coverage is 83.02%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #262      +/-   ##
==========================================
+ Coverage   71.84%   72.53%   +0.69%     
==========================================
  Files          49       51       +2     
  Lines        2515     2713     +198     
==========================================
+ Hits         1807     1968     +161     
- Misses        708      745      +37     
Impacted Files Coverage Δ
src/default_headers.rs 100.00% <ø> (ø)
src/interceptor/mod.rs 0.00% <0.00%> (ø)
src/redirect.rs 76.47% <ø> (ø)
src/request.rs 27.45% <ø> (ø)
tests/redirects.rs 100.00% <ø> (ø)
src/headers.rs 47.05% <47.05%> (-52.95%) ⬇️
src/response.rs 60.86% <66.66%> (-21.49%) ⬇️
src/client.rs 65.63% <69.13%> (-4.03%) ⬇️
src/body/mod.rs 81.30% <81.30%> (ø)
src/body/sync.rs 81.81% <81.81%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a399a2...936970e. Read the comment docs.

@sagebind sagebind marked this pull request as ready for review November 28, 2020 18:21
@sagebind sagebind merged commit 5b17d4c into master Nov 28, 2020
@sagebind sagebind deleted the split-sync-async-body branch November 28, 2020 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split sync and async response APIs
1 participant