use boxed trait method where appropriate

This commit is contained in:
Rob Ede 2021-12-17 00:09:11 +00:00
parent 88a1999c06
commit 240c85260b
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
4 changed files with 4 additions and 7 deletions

View File

@ -194,7 +194,7 @@ impl<B> Response<B> {
where where
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
self.map_body(|_, body| BoxBody::new(body)) self.map_body(|_, body| body.boxed())
} }
/// Returns body, consuming this response. /// Returns body, consuming this response.

View File

@ -45,9 +45,7 @@ impl AnyBody {
where where
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
Self::Body { Self::Body { body: body.boxed() }
body: BoxBody::new(body),
}
} }
/// Constructs new `AnyBody` instance from a slice of bytes by copying it. /// Constructs new `AnyBody` instance from a slice of bytes by copying it.

View File

@ -244,8 +244,7 @@ impl<B> HttpResponse<B> {
where where
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
// TODO: avoid double boxing with down-casting, if it improves perf self.map_body(|_, body| body.boxed())
self.map_body(|_, body| BoxBody::new(body))
} }
/// Extract response body /// Extract response body

View File

@ -451,7 +451,7 @@ impl<B> ServiceResponse<B> {
where where
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
self.map_body(|_, body| BoxBody::new(body)) self.map_body(|_, body| body.boxed())
} }
} }