diff --git a/src/error.rs b/src/error.rs index 0fd37b6..7165a64 100644 --- a/src/error.rs +++ b/src/error.rs @@ -416,4 +416,12 @@ mod tests { let _error: Box = Box::new(Error::new(ErrorKind::Io, None)); let _error: Box = Box::new(Error::new(ErrorKind::Io, None)); } + + #[test] + fn ensure_error_size() { + // This is platform dependent, so we can't be too strict or precise. + let size = std::mem::size_of::(); + println!("Error size: {}", size); + assert!(size < 500); // 344 on Macbook M1 + } } diff --git a/src/pool.rs b/src/pool.rs index 26ad5a1..dcb73ec 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -225,13 +225,13 @@ impl PoolKey { /// *Internal API* pub(crate) struct PoolReturnRead> { // unit that contains the agent where we want to return the reader. - unit: Option, + unit: Option>, // wrapped reader around the same stream reader: Option, } impl> PoolReturnRead { - pub fn new(unit: Option, reader: R) -> Self { + pub fn new(unit: Option>, reader: R) -> Self { PoolReturnRead { unit, reader: Some(reader), diff --git a/src/response.rs b/src/response.rs index c170e8c..922cba1 100644 --- a/src/response.rs +++ b/src/response.rs @@ -58,8 +58,10 @@ pub struct Response { index: ResponseStatusIndex, status: u16, headers: Vec
, - unit: Option, - stream: Stream, + // Boxed to avoid taking up too much size. + unit: Option>, + // Boxed to avoid taking up too much size. + stream: Box, /// The redirect history of this response, if any. The history starts with /// the first response received and ends with the response immediately /// previous to this one. @@ -255,7 +257,7 @@ impl Response { .map(|c| c.eq_ignore_ascii_case("close")) .unwrap_or(false); - let is_head = (&self.unit).as_ref().map(|u| u.is_head()).unwrap_or(false); + let is_head = self.unit.as_ref().map(|u| u.is_head()).unwrap_or(false); let has_no_body = is_head || match self.status { 204 | 304 => true, @@ -288,7 +290,7 @@ impl Response { } } let deadline = unit.as_ref().and_then(|u| u.deadline); - let stream = DeadlineStream::new(stream, deadline); + let stream = DeadlineStream::new(*stream, deadline); match (use_chunked, limit_bytes) { (true, _) => Box::new(PoolReturnRead::new(unit, ChunkDecoder::new(stream))), @@ -482,8 +484,8 @@ impl Response { index, status, headers, - unit, - stream: stream.into(), + unit: unit.map(Box::new), + stream: Box::new(stream.into()), history: vec![], }) } @@ -955,4 +957,12 @@ mod tests { let _response: Box = Box::new(Response::new(302, "Found", "").unwrap()); let _response: Box = Box::new(Response::new(302, "Found", "").unwrap()); } + + #[test] + fn ensure_response_size() { + // This is platform dependent, so we can't be too strict or precise. + let size = std::mem::size_of::(); + println!("Response size: {}", size); + assert!(size < 400); // 200 on Macbook M1 + } }