pub enum Body {
    Bytes(Bytes),
    MoreBytes(MoreBytes),
    HyperBody(HyperBodyStream),
    AsyncRead(Pin<Box<dyn AsyncRead + Send + Sync + 'static, Global>>),
    BytesStream(Pin<Box<dyn BytesStream + Send + Sync + 'static, Global>>),
    Empty,
}
Expand description

The body for any request or response.

Variants

Bytes(Bytes)

MoreBytes(MoreBytes)

HyperBody(HyperBodyStream)

only available if the feature hyper_body is enabled.

AsyncRead(Pin<Box<dyn AsyncRead + Send + Sync + 'static, Global>>)

BytesStream(Pin<Box<dyn BytesStream + Send + Sync + 'static, Global>>)

Empty

Implementations

Creates a new empty body.

Creates a new body with the give bytes, an empty body is returned if bytes is empty.

Creates a new Body::Bytes from the given bytes if the slice is not empty.

Returns if self is Body::Empty.

Returns this instance and replaces self with Body::empty.

Replaces the body with a new one.

Returns a length if it is already known.

Note

Body::Empty is returned as Some(0).

Creates a new Body from an AsyncRead implementation. This puts the AsyncRead in a box.

Creates a new Body from an BytesStream implementation. This puts the BytesStream in a box.

Creates a new Body from a hyper Body. Aftwards you can set a size limit with set_size_limit.

Note

Works only with the hyper_body feature.

Sets a read size limit to the HyperBody. Returns true if the size limit was set.

Note

Works only with the hyper_body feature.
When the size limit is reached an io::Error::Other with SizeLimitReached is returned.

Panics while reading

If the body was already read more than the max_size or the max_size is 0.

Converts the Body to a StreamHttpBody which implements http_body::Body, useful when using hyper.

Converts the Body to a boxed BytesStream.

Converts the Body to a boxed AsyncRead.

Converts the body into MoreBytes returning an error if reading failed or the size limit was reached.

Converts the body into a Vector.

Note

If possible, avoid this function as it is really inefficient.

Converts the body into a String.

Note

If possible, avoid this function as it is really inefficient.
For tests or quick debugging however it is quite suitable.

Converts the body into to Body::Bytes, returning the slice.

Note

If possible, avoid this function as it is really inefficient.

Writes the entire body to an AsyncWrite implementer.

Creates a Body with a timeout.

Note

The timer starts when the first read is performed.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more