Add Send + Sync marker traits to into_reader.

This allows the resulting Read to be shared among threads.
This commit is contained in:
Jacob Hoffman-Andrews
2020-09-25 00:07:28 -07:00
committed by Martin Algesten
parent 7046b07518
commit 5e00b5c5e3
2 changed files with 4 additions and 5 deletions

View File

@@ -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<dyn Read>
}
(true, _) => Box::new(PoolReturnRead::new(unit, ChunkDecoder::new(stream)))
as Box<dyn Read + Send + Sync>,
(false, Some(len)) => {
Box::new(PoolReturnRead::new(unit, LimitedRead::new(stream, len)))
}

View File

@@ -32,7 +32,7 @@ pub enum Stream {
Https(BufReader<TlsStream<TcpStream>>),
Cursor(Cursor<Vec<u8>>),
#[cfg(test)]
Test(Box<dyn BufRead + Send>, Vec<u8>),
Test(Box<dyn BufRead + Send + Sync>, Vec<u8>),
}
// DeadlineStream wraps a stream such that read() will return an error