Build a blocking body from bytes::Bytes to allow copy-free chained network calls. #1114
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.
Currently, if I want to use the
reqwest::blocking::Client
, the response can give me abytes::Bytes
but afaik there is no easy/cheap way to turn that into an owned contiguous bytes type needed to build a blocking body. As of 0.10.10, a blocking body can be constructed from a file,&'static [u8]
,String
,&'static str
, and Vec.The async API DOES allow a body to be built from
Bytes
which is extremely convenient for getting bytes from one url and putting them at another url. My application would benefit greatly from minimizing copying bytes in these get-put chains and this trait implementation seems to be a natural way to address what I imagine is not an extremely uncommon use case. This trait implementation in the blocking API IMO makes sense with the design philosophy of the library, makes the blocking API more consistent with the async one, and allows greater composability within and between the clients.While this seems like the simplest/minimal change that will effectively address this pattern of guiding bytes from a get response to a put request, other alternatives to this trait implementation include:
blocking::Response.vec()
or something) (I dont want to usestd::String
as an intermediate step)impl<T: AsRef<[u8]>> From<T> for blocking::Body
bytes::Bytes
into aVec<u8>
without copying the bytes?