logo
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

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