From 5e00b5c5e3240f868c8b7a465759b687d427751b Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Fri, 25 Sep 2020 00:07:28 -0700 Subject: [PATCH] Add Send + Sync marker traits to into_reader. This allows the resulting Read to be shared among threads. --- src/response.rs | 7 +++---- src/stream.rs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/response.rs b/src/response.rs index 3e7dcc5..a0fe15e 100644 --- a/src/response.rs +++ b/src/response.rs @@ -288,7 +288,7 @@ impl Response { /// assert_eq!(bytes.len(), len); /// # } /// ``` - pub fn into_reader(self) -> impl Read { + pub fn into_reader(self) -> impl Read + Send + Sync { // let is_http10 = self.http_version().eq_ignore_ascii_case("HTTP/1.0"); let is_close = self @@ -326,9 +326,8 @@ impl Response { let stream = DeadlineStream::new(stream, deadline); match (use_chunked, limit_bytes) { - (true, _) => { - Box::new(PoolReturnRead::new(unit, ChunkDecoder::new(stream))) as Box - } + (true, _) => Box::new(PoolReturnRead::new(unit, ChunkDecoder::new(stream))) + as Box, (false, Some(len)) => { Box::new(PoolReturnRead::new(unit, LimitedRead::new(stream, len))) } diff --git a/src/stream.rs b/src/stream.rs index 5c79547..ff0faee 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -32,7 +32,7 @@ pub enum Stream { Https(BufReader>), Cursor(Cursor>), #[cfg(test)] - Test(Box, Vec), + Test(Box, Vec), } // DeadlineStream wraps a stream such that read() will return an error