logo
pub trait MessageBody {
    type Error: Into<Box<dyn Error + 'static, Global>>;
    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> { ... }
fn boxed(self) -> BoxBody
    where
        Self: 'static
, { ... } }
Expand description

An interface types that can converted to bytes and used as response bodies.

Associated Types

The type of error that will be returned if streaming body fails.

Since it is not appropriate to generate a response mid-stream, it only requires Error for internal use and logging.

Required methods

Body size hint.

If BodySize::None is returned, optimizations that skip reading the body are allowed.

Attempt to pull out the next chunk of body bytes.

Provided methods

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.

Converts this body into BoxBody.

Implementations on Foreign Types

Implementors