Skip to main content

Body

Trait Body 

Source
pub trait Body {
    type Data;
    type Error;

    // Required method
    fn poll_frame(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>;

    // Provided methods
    fn is_end_stream(&self) -> bool { ... }
    fn size_hint(&self) -> SizeHint { ... }
}
Expand description

An asynchronous streaming body composed of Frames.

Each frame is either a Frame::Data carrying payload bytes or a Frame::Trailers carrying trailing headers. The stream signals completion by returning Poll::Ready(None).

Required Associated Types§

Source

type Data

The payload data type yielded by Frame::Data variants.

Source

type Error

The error type that can occur while producing frames.

Required Methods§

Source

fn poll_frame( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>

Attempt to pull the next frame from the body.

§Return values
  • Poll::Pending — the next frame is not yet available.
  • Poll::Ready(Some(Ok(frame))) — a Frame::Data or Frame::Trailers frame.
  • Poll::Ready(Some(Err(e))) — a terminal error; no further frames will be produced.
  • Poll::Ready(None) — the body is fully consumed.

Provided Methods§

Source

fn is_end_stream(&self) -> bool

Indicates whether the body has been fully consumed.

  • true — the body is exhausted and Body::poll_frame should not be called again.
  • false — the body may still have frames to yield, or its state is unknown.

Implementors SHOULD override this method when possible. Accurate reporting improves correctness and performance of consumers that can skip polling when the body is empty.

Source

fn size_hint(&self) -> SizeHint

Returns a hint about the total size of the remaining Frame::Data payload.

The hint applies only to data frames; trailer frames are not included.

Implementors SHOULD override this method when possible. An accurate size hint allows consumers to pre-allocate buffers and set content-length headers.

Implementations on Foreign Types§

Source§

impl<B> Body for Box<B>
where B: Body + Unpin + ?Sized,

Source§

type Data = <B as Body>::Data

Source§

type Error = <B as Body>::Error

Source§

fn poll_frame( self: Pin<&mut Box<B>>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<<Box<B> as Body>::Data>, <Box<B> as Body>::Error>>>

Source§

fn is_end_stream(&self) -> bool

Source§

fn size_hint(&self) -> SizeHint

Source§

impl<B> Body for Pin<B>
where B: DerefMut, <B as Deref>::Target: Body,

Source§

type Data = <<B as Deref>::Target as Body>::Data

Source§

type Error = <<B as Deref>::Target as Body>::Error

Source§

fn poll_frame( self: Pin<&mut Pin<B>>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<<Pin<B> as Body>::Data>, <Pin<B> as Body>::Error>>>

Source§

fn is_end_stream(&self) -> bool

Source§

fn size_hint(&self) -> SizeHint

Implementors§

Source§

impl Body for RequestBody

Source§

impl Body for BoxBody

Source§

impl<B> Body for RequestExt<B>
where B: Body,

Source§

type Data = <B as Body>::Data

Source§

type Error = <B as Body>::Error

Source§

impl<B> Body for Data<B>
where B: Body,

Source§

type Data = <B as Body>::Data

Source§

type Error = <B as Body>::Error

Source§

impl<B, E> Body for ResponseBody<B>
where B: Body<Data = Bytes, Error = E>,

Source§

impl<D> Body for Empty<D>

Source§

impl<D> Body for Full<D>
where D: Buf,

Source§

impl<D> Body for Trailers<D>

Source§

impl<L, R> Body for Either<L, R>
where L: Body, R: Body<Data = <L as Body>::Data>, <R as Body>::Error: From<<L as Body>::Error>,

Source§

type Data = <L as Body>::Data

Source§

type Error = <R as Body>::Error

Source§

impl<S, D, E> Body for StreamBody<S>
where S: Stream<Item = Result<Frame<D>, E>>,

Source§

type Data = D

Source§

type Error = E

Source§

impl<S, T, E> Body for StreamDataBody<S>
where S: Stream<Item = Result<T, E>>,

Source§

type Data = T

Source§

type Error = E