Trait actix_http::body::MessageBody
source · [−]pub trait MessageBody {
type Error: Into<Box<dyn StdError>>;
fn size(&self) -> BodySize;
fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Option<Result<Bytes, Self::Error>>>;
fn try_into_bytes(self) -> Result<Bytes, Self>
where
Self: Sized,
{ ... }
fn boxed(self) -> BoxBody
where
Self: Sized + 'static,
{ ... }
}
Expand description
An interface types that can converted to bytes and used as response bodies.
Required Associated Types
Required Methods
Body size hint.
If BodySize::None
is returned, optimizations that skip reading the body are allowed.
Provided Methods
fn try_into_bytes(self) -> Result<Bytes, Self> where
Self: Sized,
fn try_into_bytes(self) -> Result<Bytes, Self> where
Self: Sized,
Try to convert into the complete chunk of body bytes.
Implement this method if the entire body can be trivially extracted. This is useful for
optimizations where poll_next
calls can be avoided.
Body types with BodySize::None
are allowed to return empty Bytes
. Although, if calling
this method, it is recommended to check size
first and return early.
Errors
The default implementation will error and return the original type back to the caller for further use.