mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
improve codegen on BoxBody poll_next
This commit is contained in:
parent
aa31086af5
commit
1d6f5ba6d6
@ -77,17 +77,21 @@ impl MessageBody for BoxBody {
|
|||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
) -> Poll<Option<Result<Bytes, Self::Error>>> {
|
) -> Poll<Option<Result<Bytes, Self::Error>>> {
|
||||||
match &mut self.0 {
|
match &mut self.0 {
|
||||||
BoxBodyInner::None(_) => Poll::Ready(None),
|
BoxBodyInner::None(body) => {
|
||||||
BoxBodyInner::Bytes(bytes) => Pin::new(bytes).poll_next(cx).map_err(Into::into),
|
Pin::new(body).poll_next(cx).map_err(|err| match err {})
|
||||||
BoxBodyInner::Stream(stream) => Pin::new(stream).poll_next(cx),
|
}
|
||||||
|
BoxBodyInner::Bytes(body) => {
|
||||||
|
Pin::new(body).poll_next(cx).map_err(|err| match err {})
|
||||||
|
}
|
||||||
|
BoxBodyInner::Stream(body) => Pin::new(body).poll_next(cx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn try_into_bytes(self) -> Result<Bytes, Self> {
|
fn try_into_bytes(self) -> Result<Bytes, Self> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
BoxBodyInner::None(none) => Ok(none.try_into_bytes().unwrap()),
|
BoxBodyInner::None(body) => Ok(body.try_into_bytes().unwrap()),
|
||||||
BoxBodyInner::Bytes(bytes) => Ok(bytes.try_into_bytes().unwrap()),
|
BoxBodyInner::Bytes(body) => Ok(body.try_into_bytes().unwrap()),
|
||||||
_ => Err(self),
|
_ => Err(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,8 @@ pub trait MessageBody {
|
|||||||
|
|
||||||
/// Convert this body into `Bytes`.
|
/// Convert this body into `Bytes`.
|
||||||
///
|
///
|
||||||
/// Bodies with `BodySize::None` are allowed to return empty `Bytes`.
|
/// Body types with `BodySize::None` are allowed to return empty `Bytes`.
|
||||||
|
#[inline]
|
||||||
fn try_into_bytes(self) -> Result<Bytes, Self>
|
fn try_into_bytes(self) -> Result<Bytes, Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
@ -139,6 +140,7 @@ mod foreign_impls {
|
|||||||
BodySize::Sized(self.len() as u64)
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
@ -164,6 +166,7 @@ mod foreign_impls {
|
|||||||
BodySize::Sized(self.len() as u64)
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
@ -189,6 +192,7 @@ mod foreign_impls {
|
|||||||
BodySize::Sized(self.len() as u64)
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
@ -214,6 +218,7 @@ mod foreign_impls {
|
|||||||
BodySize::Sized(self.len() as u64)
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
@ -239,6 +244,7 @@ mod foreign_impls {
|
|||||||
BodySize::Sized(self.len() as u64)
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
@ -266,6 +272,7 @@ mod foreign_impls {
|
|||||||
BodySize::Sized(self.len() as u64)
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
@ -292,6 +299,7 @@ mod foreign_impls {
|
|||||||
BodySize::Sized(self.len() as u64)
|
BodySize::Sized(self.len() as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn poll_next(
|
fn poll_next(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
|
@ -108,6 +108,7 @@ where
|
|||||||
{
|
{
|
||||||
type Error = EncoderError;
|
type Error = EncoderError;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn size(&self) -> BodySize {
|
fn size(&self) -> BodySize {
|
||||||
match self {
|
match self {
|
||||||
EncoderBody::None => BodySize::None,
|
EncoderBody::None => BodySize::None,
|
||||||
@ -131,6 +132,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn try_into_bytes(self) -> Result<Bytes, Self>
|
fn try_into_bytes(self) -> Result<Bytes, Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
@ -149,6 +151,7 @@ where
|
|||||||
{
|
{
|
||||||
type Error = EncoderError;
|
type Error = EncoderError;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn size(&self) -> BodySize {
|
fn size(&self) -> BodySize {
|
||||||
if self.encoder.is_some() {
|
if self.encoder.is_some() {
|
||||||
BodySize::Stream
|
BodySize::Stream
|
||||||
@ -225,6 +228,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn try_into_bytes(mut self) -> Result<Bytes, Self>
|
fn try_into_bytes(mut self) -> Result<Bytes, Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
Loading…
Reference in New Issue
Block a user