Struct trillium_http::Body
source · 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
type.
Implementations§
source§impl Body
impl Body
sourcepub fn new_streaming(
async_read: impl AsyncRead + Send + Sync + 'static,
len: Option<u64>
) -> Self
pub fn new_streaming( async_read: impl AsyncRead + Send + Sync + 'static, len: Option<u64> ) -> Self
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.
sourcepub fn new_static(content: impl Into<Cow<'static, [u8]>>) -> Self
pub fn new_static(content: impl Into<Cow<'static, [u8]>>) -> Self
Construct a fixed-length Body from a Vec<u8>
or &'static [u8]
.
sourcepub 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.
sourcepub fn into_reader(self) -> Pin<Box<dyn AsyncRead + Send + Sync>>
pub fn into_reader(self) -> Pin<Box<dyn AsyncRead + Send + Sync>>
Transform this Body into a dyn AsyncRead
. This will wrap
static content in a [Cursor
]. Note that this is different
from reading directly from the Body, which includes chunked
encoding.
sourcepub async fn into_bytes(self) -> Result<Cow<'static, [u8]>>
pub async fn into_bytes(self) -> Result<Cow<'static, [u8]>>
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 read to completion.
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
sourcepub fn bytes_read(&self) -> u64
pub fn bytes_read(&self) -> u64
Retrieve the number of bytes that have been read from this body
sourcepub fn len(&self) -> Option<u64>
pub fn len(&self) -> Option<u64>
returns the content length of this body, if known and available.
sourcepub fn is_streaming(&self) -> bool
pub fn is_streaming(&self) -> bool
determine if the this body represents streaming content
Trait Implementations§
source§impl AsyncRead for Body
impl AsyncRead for Body
source§impl<Transport> From<ReceivedBody<'static, Transport>> for Body
impl<Transport> From<ReceivedBody<'static, Transport>> for Body
source§fn from(rb: ReceivedBody<'static, Transport>) -> Self
fn from(rb: ReceivedBody<'static, Transport>) -> Self
Auto Trait Implementations§
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