pub enum Body {
Empty,
Bytes(Vec<u8>),
Stream(RequestBodyStream),
}Expand description
Request body.
Variants§
Empty
Empty body.
Bytes(Vec<u8>)
Bytes body.
Stream(RequestBodyStream)
Streaming body for large uploads.
This variant enables memory-efficient handling of large request bodies by yielding chunks incrementally rather than buffering the entire content.
The stream yields Result<Vec<u8>, RequestBodyStreamError> chunks.
Implementations§
Source§impl Body
impl Body
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Get body as bytes, consuming it.
For Body::Stream, this will panic. Use into_bytes_async() instead
for streaming bodies, or check with is_streaming() first.
Sourcepub async fn into_bytes_async(self) -> Result<Vec<u8>, RequestBodyStreamError>
pub async fn into_bytes_async(self) -> Result<Vec<u8>, RequestBodyStreamError>
Get body as bytes asynchronously, consuming it.
This works for all body types:
Emptyreturns an empty VecBytesreturns the bytesStreamcollects all chunks into a Vec
§Errors
Returns an error if the stream encounters an error while reading.
Sourcepub fn is_streaming(&self) -> bool
pub fn is_streaming(&self) -> bool
Check if body is a streaming body.
Sourcepub fn take_stream(self) -> Option<RequestBodyStream>
pub fn take_stream(self) -> Option<RequestBodyStream>
Take the body stream, if this is a streaming body.
Returns None for Empty and Bytes variants.
Sourcepub fn streaming_with_size<S>(stream: S, size: usize) -> Self
pub fn streaming_with_size<S>(stream: S, size: usize) -> Self
Create a streaming body with a known size.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Body
impl !RefUnwindSafe for Body
impl Send for Body
impl Sync for Body
impl Unpin for Body
impl !UnwindSafe 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).