pub struct Body(/* private fields */);
Expand description
HTTP request body.
Use TryBody
to convert types to body.
Implementations§
source§impl Body
impl Body
sourcepub fn empty() -> Body
pub fn empty() -> Body
Create a new empty body.
An empty body represents the absence of a body, which is semantically different than the presence of a body of zero length.
sourcepub fn from_bytes_static(bytes: impl AsRef<[u8]> + 'static) -> Self
pub fn from_bytes_static(bytes: impl AsRef<[u8]> + 'static) -> Self
Create a new body from a potentially static byte buffer.
The body will have a known length equal to the number of bytes given.
This will try to prevent a copy if the type passed in can be re-used, otherwise the buffer will be copied first. This method guarantees to not require a copy for the following types:
sourcepub fn from_reader(read: impl AsyncRead + Send + Sync + 'static) -> Self
pub fn from_reader(read: impl AsyncRead + Send + Sync + 'static) -> Self
Create a streaming body of unknown length.
sourcepub fn from_reader_sized(
read: impl AsyncRead + Send + Sync + 'static,
size: u64,
) -> Self
pub fn from_reader_sized( read: impl AsyncRead + Send + Sync + 'static, size: u64, ) -> Self
Create a streaming body of with known length.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Report if this body is empty.
This is not necessarily the same as checking for zero length, since HTTP message bodies are optional,
there is a semantic difference between the absence of a body and the presence of a zero-length body.
This method will only return true
for the former.
sourcepub fn reset(&mut self) -> bool
pub fn reset(&mut self) -> bool
If this body is repeatable, reset the body stream back to the start of the content.
Returns false if the body cannot be reset.
sourcepub async fn text_utf8(&mut self) -> Result<Txt, Box<dyn Error>>
pub async fn text_utf8(&mut self) -> Result<Txt, Box<dyn Error>>
Read the body and try to convert to UTF-8.
Consider using Response::text
, it uses the header encoding information if available.
sourcepub async fn read(&mut self, buf: &mut [u8]) -> Result<usize>
pub async fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Read some bytes from the body, returns how many bytes where read.
sourcepub async fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
pub async fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
Read the from the body to exactly fill the buffer.
Trait Implementations§
source§impl AsyncRead for Body
impl AsyncRead for Body
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§
§impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
§fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
buf
. Read more§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit
bytes from it. Read more§impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where
Self: Unpin,
§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectoredFuture<'a, Self>where
Self: Unpin,
§fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8>,
) -> ReadToEndFuture<'a, Self>where
Self: Unpin,
§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToStringFuture<'a, Self>where
Self: Unpin,
§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where
Self: Unpin,
buf
. Read more§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit
bytes from it. Read moresource§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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more