diff --git a/actix-http/src/body/body.rs b/actix-http/src/body/body.rs index dfb3da1a5..4c95bd31a 100644 --- a/actix-http/src/body/body.rs +++ b/actix-http/src/body/body.rs @@ -184,6 +184,7 @@ where pub struct BoxAnyBody(Pin>>>); impl BoxAnyBody { + /// Boxes a `MessageBody` and any errors it generates. pub fn from_body(body: B) -> Self where B: MessageBody + 'static, diff --git a/actix-http/src/body/message_body.rs b/actix-http/src/body/message_body.rs index f24c29acb..2d2642ba7 100644 --- a/actix-http/src/body/message_body.rs +++ b/actix-http/src/body/message_body.rs @@ -1,6 +1,7 @@ //! [`MessageBody`] trait and foreign implementations. use std::{ + convert::Infallible, mem, pin::Pin, task::{Context, Poll}, @@ -29,7 +30,7 @@ pub trait MessageBody { } impl MessageBody for () { - type Error = Error; + type Error = Infallible; fn size(&self) -> BodySize { BodySize::Empty @@ -43,12 +44,12 @@ impl MessageBody for () { } } -impl MessageBody for Box +impl MessageBody for Box where - T: MessageBody + Unpin, - T::Error: Into, + B: MessageBody + Unpin, + B::Error: Into, { - type Error = Error; + type Error = B::Error; fn size(&self) -> BodySize { self.as_ref().size() @@ -58,20 +59,16 @@ where self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll>> { - match ready!(Pin::new(self.get_mut().as_mut()).poll_next(cx)) { - Some(Err(err)) => Poll::Ready(Some(Err(err.into()))), - Some(Ok(val)) => Poll::Ready(Some(Ok(val))), - None => Poll::Ready(None), - } + Pin::new(self.get_mut().as_mut()).poll_next(cx) } } -impl MessageBody for Pin> +impl MessageBody for Pin> where - T: MessageBody, - T::Error: Into, + B: MessageBody, + B::Error: Into, { - type Error = Error; + type Error = B::Error; fn size(&self) -> BodySize { self.as_ref().size() @@ -81,16 +78,12 @@ where mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll>> { - match ready!(self.as_mut().poll_next(cx)) { - Some(Err(err)) => Poll::Ready(Some(Err(err))), - Some(Ok(val)) => Poll::Ready(Some(Ok(val))), - None => Poll::Ready(None), - } + self.as_mut().poll_next(cx) } } impl MessageBody for Bytes { - type Error = Error; + type Error = Infallible; fn size(&self) -> BodySize { BodySize::Sized(self.len() as u64) @@ -109,7 +102,7 @@ impl MessageBody for Bytes { } impl MessageBody for BytesMut { - type Error = Error; + type Error = Infallible; fn size(&self) -> BodySize { BodySize::Sized(self.len() as u64) @@ -128,7 +121,7 @@ impl MessageBody for BytesMut { } impl MessageBody for &'static str { - type Error = Error; + type Error = Infallible; fn size(&self) -> BodySize { BodySize::Sized(self.len() as u64) @@ -149,7 +142,7 @@ impl MessageBody for &'static str { } impl MessageBody for Vec { - type Error = Error; + type Error = Infallible; fn size(&self) -> BodySize { BodySize::Sized(self.len() as u64) @@ -168,7 +161,7 @@ impl MessageBody for Vec { } impl MessageBody for String { - type Error = Error; + type Error = Infallible; fn size(&self) -> BodySize { BodySize::Sized(self.len() as u64) diff --git a/actix-http/src/error.rs b/actix-http/src/error.rs index 4daf245f6..c92f9076d 100644 --- a/actix-http/src/error.rs +++ b/actix-http/src/error.rs @@ -106,8 +106,7 @@ impl From<()> for Error { impl From for Error { fn from(_: std::convert::Infallible) -> Self { - // `std::convert::Infallible` indicates an error - // that will never happen + // hint that an error that will never happen unreachable!() } }