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§
Sourcetype Data
type Data
The payload data type yielded by Frame::Data variants.
Required Methods§
Sourcefn poll_frame(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>
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)))— aFrame::DataorFrame::Trailersframe.Poll::Ready(Some(Err(e)))— a terminal error; no further frames will be produced.Poll::Ready(None)— the body is fully consumed.
Provided Methods§
Sourcefn is_end_stream(&self) -> bool
fn is_end_stream(&self) -> bool
Indicates whether the body has been fully consumed.
true— the body is exhausted andBody::poll_frameshould 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.
Sourcefn size_hint(&self) -> SizeHint
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.