pub enum Body {
Empty,
Bytes(Bytes),
Stream(BodyStream),
}Expand description
An HTTP response body: nothing, some bytes, or a stream of chunks.
Variants§
Empty
No body at all — distinct from a zero-length one, so 204 No Content
can omit Content-Length entirely.
Bytes(Bytes)
A body already in memory. Its length is known, so Content-Length can
be set.
Stream(BodyStream)
A body produced incrementally. Its length is unknown, so it goes out chunked.
Implementations§
Source§impl Body
impl Body
Sourcepub fn from_bytes(bytes: impl Into<Bytes>) -> Self
pub fn from_bytes(bytes: impl Into<Bytes>) -> Self
A body from anything byte-like.
Sourcepub fn from_stream<S>(stream: S) -> Self
pub fn from_stream<S>(stream: S) -> Self
A streaming body.
Sourcepub fn size_hint(&self) -> Option<u64>
pub fn size_hint(&self) -> Option<u64>
The body’s length in bytes, when it is known up front. None for a
stream.
Trait Implementations§
Source§impl Body for Body
Lets a Body be handed straight to hyper, which writes responses through
the http-body trait.
impl Body for Body
Lets a Body be handed straight to hyper, which writes responses through
the http-body trait.
Source§impl IntoResponse for Body
impl IntoResponse for Body
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Build the response.
Auto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more