Struct Body
pub struct Body(/* private fields */);Expand description
The trillium representation of a http body. This can contain
either &'static [u8] content, Vec<u8> content, or a boxed
AsyncRead/BodySource type.
Implementations§
§impl Body
impl Body
pub fn new_streaming(
async_read: impl AsyncRead + Send + 'static,
len: Option<u64>,
) -> Body
pub fn new_streaming( async_read: impl AsyncRead + Send + 'static, len: Option<u64>, ) -> Body
Construct a new body from a streaming AsyncRead source. If
you have the body content in memory already, prefer
Body::new_static or one of the From conversions.
pub fn new_with_trailers(body: impl BodySource, len: Option<u64>) -> Body
pub fn new_with_trailers(body: impl BodySource, len: Option<u64>) -> Body
Construct a new body from a BodySource that can produce trailers after
the body has been fully read.
Use this when trailers must be computed dynamically from the body bytes, for example to append a content hash.
pub fn new_static(content: impl Into<Cow<'static, [u8]>>) -> Body
pub fn new_static(content: impl Into<Cow<'static, [u8]>>) -> Body
Construct a fixed-length Body from a Vec<u8> or &'static [u8].
pub fn static_bytes(&self) -> Option<&[u8]>
pub fn static_bytes(&self) -> Option<&[u8]>
Retrieve a borrow of the static content in this body. If this body is a streaming body or an empty body, this will return None.
pub async fn into_bytes(self) -> Result<Cow<'static, [u8]>, Error>
pub async fn into_bytes(self) -> Result<Cow<'static, [u8]>, Error>
Consume this body and return the full content. If the body was
constructed with Body::new_streaming, this will read the
entire streaming body into memory, awaiting the streaming
source’s completion. This function will return an error if a
streaming body has already been partially or fully read.
§Errors
This returns an error variant if either of the following conditions are met:
there is an io error when reading from the underlying transport such as a disconnect the body has already been read to completion
pub fn bytes_read(&self) -> u64
pub fn bytes_read(&self) -> u64
Retrieve the number of bytes that have been read from this body
pub fn is_streaming(&self) -> bool
pub fn is_streaming(&self) -> bool
determine if the this body represents streaming content
Trait Implementations§
§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 UnsafeUnpin for Body
impl !UnwindSafe for Body
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§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,
Source§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,
Source§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,
Source§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,
Source§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 moreSource§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