pub struct Body(/* private fields */);Expand description
The body type used in axum requests and responses.
Implementations§
Source§impl Body
impl Body
Sourcepub fn unknown() -> Body
pub fn unknown() -> Body
Create a body of unknown size.
This is useful in cases where a body is required to construct a response, but the size of the body is not known.
For example, this can be used to respond to HEAD requests,
for which the body of the corresponding GET request would be expensive
to compute. Note that this particular case is also mentioned in
RFC 9110 (Section 9.3.2, Paragraph 2).
The most notable difference compared to an empty body as returned by
Body::empty lies in the upper bound returned by Body::size_hint:
The upper bound of the size of an empty body is 0 bytes, while there
is no upper bound for the size of an unknown body.
Other than the size hint, an unknown body behaves like an empty body,
i.e., Body::is_end_stream returns true, and when polled via
Body::poll_frame, it immediately returns Poll::Ready(None).
Sourcepub fn from_stream<S>(stream: S) -> Body
pub fn from_stream<S>(stream: S) -> Body
Create a new Body from a Stream.
Sourcepub fn into_data_stream(self) -> BodyDataStream
pub fn into_data_stream(self) -> BodyDataStream
Convert the body into a [Stream] of data frames.
Non-data frames (such as trailers) will be discarded. Use http_body_util::BodyStream if
you need a [Stream] of all frame types.
Trait Implementations§
Source§impl Body for Body
impl Body for Body
Source§fn poll_frame(
self: Pin<&mut Body>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<<Body as Body>::Data>, <Body as Body>::Error>>>
fn poll_frame( self: Pin<&mut Body>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<<Body as Body>::Data>, <Body as Body>::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 moreSource§impl<S> FromRequest<S> for Body
impl<S> FromRequest<S> for Body
Source§impl IntoResponse for Body
impl IntoResponse for Body
Source§fn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
Auto Trait Implementations§
impl !RefUnwindSafe for Body
impl !Sync for Body
impl !UnwindSafe for Body
impl Freeze for Body
impl Send for Body
impl Unpin for Body
impl UnsafeUnpin for Body
Blanket Implementations§
§impl<T> BodyExt for Twhere
T: Body + ?Sized,
impl<T> BodyExt for Twhere
T: Body + ?Sized,
§fn frame(&mut self) -> Frame<'_, Self> ⓘwhere
Self: Unpin,
fn frame(&mut self) -> Frame<'_, Self> ⓘwhere
Self: Unpin,
Frame, if any.§fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
§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.§fn with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
fn with_trailers<F>(self, trailers: F) -> WithTrailers<Self, F>
§fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
fn into_data_stream(self) -> BodyDataStream<Self>where
Self: Sized,
BodyDataStream].