Skip to content

Commit

Permalink
refactor(body): switch opt_len helper macro as function (#3483)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Dec 16, 2023
1 parent 53b560b commit d9c5d3b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/body/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,20 @@ impl Body for Incoming {
any(feature = "http1", feature = "http2"),
any(feature = "client", feature = "server")
))]
macro_rules! opt_len {
($content_length:expr) => {{
let mut hint = SizeHint::default();

if let Some(content_length) = $content_length.into_opt() {
hint.set_exact(content_length);
}

hint
}};
fn opt_len(decoded_length: DecodedLength) -> SizeHint {
if let Some(content_length) = decoded_length.into_opt() {
SizeHint::with_exact(content_length)
} else {
SizeHint::default()
}
}

match self.kind {
Kind::Empty => SizeHint::with_exact(0),
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
Kind::Chan { content_length, .. } => opt_len!(content_length),
Kind::Chan { content_length, .. } => opt_len(content_length),
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
Kind::H2 { content_length, .. } => opt_len!(content_length),
Kind::H2 { content_length, .. } => opt_len(content_length),
#[cfg(feature = "ffi")]
Kind::Ffi(..) => SizeHint::default(),
}
Expand Down

0 comments on commit d9c5d3b

Please sign in to comment.