-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add StreamReader to io module #2052
Conversation
Allow conversion from a stream of chunks of bytes to an `AsyncRead`.
At this point, I’m a bit hesitant to add more traits right now related to async-io given the current uncertainty re: future. How would this trait be used in practice? |
That's fair enough. The main use case (and what originally prompted this) is when reading a response provided by e.g. hyper. |
For some reason, I thought this was a trait... i should have paid more attention. I think an adapter is good. As I mentioned on discord, some thoughts:
Maybe something like: fn byte_stream<T: ...>(stream: T) -> ByteStream<T> { ... } I don't think |
Regarding being generic over A few naming suggestions: |
|
@carllerche ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great
# 0.2.16 (April 3, 2020) ### Fixes - sync: fix a regression where `Mutex`, `Semaphore`, and `RwLock` futures no longer implement `Sync` (#2375) - fs: fix `fs::copy` not copying file permissions (#2354) ### Added - time: added `deadline` method to `delay_queue::Expired` (#2300) - io: added `StreamReader` (#2052) Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Allow conversion from a stream of chunks of bytes to an
AsyncRead
.Motivation
Http crates such as hyper and reqwest provide their response as a stream of chunks of bytes, which is not easily convertible into a type that implements
AsyncRead
.This type was originally motivated when helping someone on the official Rust discord.
Solution
This PR provides a new type called
IntoAsyncRead
that buffers the last chunk received from the stream, and implements bothAsyncRead
andAsyncBufRead
on this new type.The futures crate has a very similar type, however that type operates on the
AsyncRead
trait from thefutures
crate as opposed to the tokio version of the trait.