pub enum Body {
Bytes(Bytes),
Stream(Pin<Box<dyn Stream<Item = Result<Bytes>> + Send + 'static>>),
}Expand description
A response body.
Construct buffered bodies with From (Body::from(bytes),
"text".into()), an empty body with Body::empty, or a streaming body
with Body::from_stream. The engine sends buffered bodies in one shot and
streamed bodies frame-by-frame.
Variants§
Bytes(Bytes)
A fully-buffered, in-memory body.
Stream(Pin<Box<dyn Stream<Item = Result<Bytes>> + Send + 'static>>)
A lazily-produced stream of byte chunks.
Implementations§
Source§impl Body
impl Body
Sourcepub fn from_stream<S, E>(stream: S) -> Self
pub fn from_stream<S, E>(stream: S) -> Self
Build a streaming body from any Stream of byte chunks. Chunk errors are
converted into Error and surface when the body is read/collected.
Sourcepub fn as_bytes(&self) -> Option<&Bytes>
pub fn as_bytes(&self) -> Option<&Bytes>
Borrow the buffered bytes, or None if this body is a stream. Used by
middleware that only post-processes already-materialized bodies.
Sourcepub fn as_slice(&self) -> Option<&[u8]>
pub fn as_slice(&self) -> Option<&[u8]>
Borrow the buffered bytes as a slice, or None for a stream.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True if this is a buffered, empty body. A stream is never reported empty (its length is unknown until read).
Sourcepub async fn into_bytes(self) -> Result<Bytes>
pub async fn into_bytes(self) -> Result<Bytes>
Collect the whole body into Bytes (returns the buffer directly when
already buffered, or drains the stream).
Trait Implementations§
Source§impl Body for Body
Body is an http_body::Body, so it can be handed to anything written
against the http/http-body crates — which is what makes the tower
adapter possible without a wrapper type at every boundary.
impl Body for Body
Body is an http_body::Body, so it can be handed to anything written
against the http/http-body crates — which is what makes the tower
adapter possible without a wrapper type at every boundary.
Source§fn poll_frame(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<Bytes>, Error>>>
fn poll_frame( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<Bytes>, Error>>>
Source§fn size_hint(&self) -> SizeHint
fn size_hint(&self) -> SizeHint
Source§fn is_end_stream(&self) -> bool
fn is_end_stream(&self) -> bool
true when the end of stream has been reached. Read moreAuto Trait Implementations§
impl !Freeze for Body
impl !RefUnwindSafe for Body
impl !Sync for Body
impl !UnwindSafe for Body
impl Send for Body
impl Unpin for Body
impl UnsafeUnpin for Body
Blanket Implementations§
Source§impl<T> BodyExt for T
impl<T> BodyExt for T
Source§fn frame(&mut self) -> Frame<'_, Self>where
Self: Unpin,
fn frame(&mut self) -> Frame<'_, Self>where
Self: Unpin,
Frame, if any.Source§fn map_frame<F, B>(self, f: F) -> MapFrame<Self, F>
fn map_frame<F, B>(self, f: F) -> MapFrame<Self, F>
Source§fn inspect_frame<F>(self, f: F) -> InspectFrame<Self, F>
fn inspect_frame<F>(self, f: F) -> InspectFrame<Self, F>
Source§fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
Source§fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
Source§fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
Source§fn collect(self) -> Collect<Self>where
Self: Sized,
fn collect(self) -> Collect<Self>where
Self: Sized,
Collected body which will collect all the DATA frames
and trailers.Source§fn with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
fn with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
Source§fn into_stream(self) -> BodyStream<Self>where
Self: Sized,
fn into_stream(self) -> BodyStream<Self>where
Self: Sized,
BodyStream.Source§fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
BodyDataStream.