Struct trillium_http::Body
source · [−]pub struct Body(_);
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
sourceimpl 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.
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
sourceimpl AsyncRead for Body
impl AsyncRead for Body
sourceimpl From<&'static [u8]> for Body
impl From<&'static [u8]> for Body
sourcefn from(content: &'static [u8]) -> Self
fn from(content: &'static [u8]) -> Self
Performs the conversion.
sourceimpl<Transport> From<ReceivedBody<'static, Transport>> for Body where
Transport: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
impl<Transport> From<ReceivedBody<'static, Transport>> for Body where
Transport: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
sourcefn from(rb: ReceivedBody<'static, Transport>) -> Self
fn from(rb: ReceivedBody<'static, Transport>) -> Self
Performs the conversion.
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
sourceimpl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
sourcefn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> where
Self: Unpin,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> where
Self: Unpin,
Reads some bytes from the byte stream. Read more
sourcefn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
sourcefn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
sourcefn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
sourcefn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> where
Self: Unpin,
Reads the exact number of bytes required to fill buf
. Read more
sourcefn take(self, limit: u64) -> Take<Self>
fn take(self, limit: u64) -> Take<Self>
Creates an adapter which will read at most limit
bytes from it. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more