diff --git a/src/pool.rs b/src/pool.rs index 0dce5ca..0b87dab 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::io::{Read, Result as IoResult}; -use crate::stream::{ReclaimStream, Stream}; +use crate::stream::Stream; use crate::unit::Unit; use url::Url; @@ -74,14 +74,14 @@ impl PoolKey { /// read is exhausted (reached a 0). /// /// *Internal API* -pub(crate) struct PoolReturnRead { +pub(crate) struct PoolReturnRead> { // unit that contains the agent where we want to return the reader. unit: Option, // wrapped reader around the same stream reader: Option, } -impl PoolReturnRead { +impl> PoolReturnRead { pub fn new(unit: Option, reader: R) -> Self { PoolReturnRead { unit, @@ -94,7 +94,7 @@ impl PoolReturnRead { if let (Some(unit), Some(reader)) = (self.unit.take(), self.reader.take()) { let state = &mut unit.agent.lock().unwrap(); // bring back stream here to either go into pool or dealloc - let stream = reader.reclaim_stream(); + let stream = reader.into(); if let Some(agent) = state.as_mut() { if !stream.is_poolable() { // just let it deallocate @@ -115,7 +115,7 @@ impl PoolReturnRead { } } -impl Read for PoolReturnRead { +impl> Read for PoolReturnRead { fn read(&mut self, buf: &mut [u8]) -> IoResult { let amount = self.do_read(buf)?; // only if the underlying reader is exhausted can we send a new @@ -127,7 +127,7 @@ impl Read for PoolReturnRead { } } -impl Drop for PoolReturnRead { +impl> Drop for PoolReturnRead { fn drop(&mut self) { self.return_connection(); } diff --git a/src/response.rs b/src/response.rs index 6dcf5e1..50e2ab2 100644 --- a/src/response.rs +++ b/src/response.rs @@ -6,7 +6,7 @@ use chunked_transfer::Decoder as ChunkDecoder; use crate::error::Error; use crate::header::Header; use crate::pool::PoolReturnRead; -use crate::stream::{ReclaimStream, Stream}; +use crate::stream::Stream; use crate::unit::Unit; #[cfg(feature = "json")] @@ -617,9 +617,12 @@ impl Read for LimitedRead { } } -impl ReclaimStream for LimitedRead { - fn reclaim_stream(self) -> Stream { - self.reader.reclaim_stream() +impl From> for Stream +where + Stream: From, +{ + fn from(limited_read: LimitedRead) -> Stream { + limited_read.reader.into() } } diff --git a/src/stream.rs b/src/stream.rs index 294864c..e01d1da 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -120,23 +120,13 @@ impl Read for Stream { } } -#[cfg(all(feature = "tls", not(feature = "native-tls")))] -pub(crate) trait ReclaimStream { - fn reclaim_stream(self) -> Stream; -} - -impl ReclaimStream for Stream { - fn reclaim_stream(self) -> Stream { - self - } -} - -impl ReclaimStream for ChunkDecoder +impl From> for Stream where R: Read, + Stream: From, { - fn reclaim_stream(self) -> Stream { - self.into_inner().reclaim_stream() + fn from(chunk_decoder: ChunkDecoder) -> Stream { + chunk_decoder.into_inner().into() } }