[−][src]Struct roa_core::Body
The Body of Request and Response.
Example
use roa_core::Body; use async_std::fs::File; use futures::io::AsyncReadExt; #[async_std::main] async fn main() -> std::io::Result<()> { let mut body = Body::default(); let mut data = String::new(); body.write_buf(b"He".as_ref()) .write_buf(b"llo, ".as_ref()) .write(File::open("../assets/author.txt").await?) .write_buf(b".".as_ref()) .read_to_string(&mut data) .await?; assert_eq!("Hello, Hexilee.", data); Ok(()) }
Methods
impl Body
[src]
pub fn write_buf(
&mut self,
buf_reader: impl BufRead + Sync + Send + Unpin + 'static
) -> &mut Self
[src]
&mut self,
buf_reader: impl BufRead + Sync + Send + Unpin + 'static
) -> &mut Self
Write reader implementing BufRead.
pub fn write(
&mut self,
reader: impl Read + Sync + Send + Unpin + 'static
) -> &mut Self
[src]
&mut self,
reader: impl Read + Sync + Send + Unpin + 'static
) -> &mut Self
Write reader implementing Read.
pub fn write_bytes(&mut self, bytes: impl Into<Vec<u8>>) -> &mut Self
[src]
Write Vec<u8>
.
pub fn write_str(&mut self, data: impl ToString) -> &mut Self
[src]
Write String
.
pub fn stream(self) -> BodyStream<Self>
[src]
Into a stream.
pub fn on_finish(
&mut self,
callback: impl 'static + Sync + Send + Unpin + Fn(&Self)
) -> &mut Self
[src]
&mut self,
callback: impl 'static + Sync + Send + Unpin + Fn(&Self)
) -> &mut Self
Callback when dropping body.
Example
use roa_core::Body; use async_std::fs::File; use futures::io::AsyncReadExt; #[async_std::test] async fn body_on_finish() -> std::io::Result<()> { let mut body = Body::default(); let mut data = String::new(); body.write_buf(b"He".as_ref()) .write_buf(b"llo, ".as_ref()) .write_buf(b"World".as_ref()) .on_finish(|body| assert_eq!(12, body.consumed())) .read_to_string(&mut data) .await?; assert_eq!("Hello, World", data); Ok(()) }
pub fn consumed(&self) -> usize
[src]
Get the numbers of consumed bytes.
Trait Implementations
impl AsyncBufRead for Body
[src]
fn poll_fill_buf(
self: Pin<&mut Self>,
cx: &mut Context
) -> Poll<Result<&[u8], Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context
) -> Poll<Result<&[u8], Error>>
fn consume(self: Pin<&mut Self>, amt: usize)
[src]
impl AsyncRead for Body
[src]
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>
impl Default for Body
[src]
impl Drop for Body
[src]
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<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<R> AsyncBufReadExt for R where
R: AsyncBufRead + ?Sized,
[src]
R: AsyncBufRead + ?Sized,
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntil<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntil<'a, Self> where
Self: Unpin,
fn read_line(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn lines(self) -> Lines<Self>
[src]
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
[src]
R: AsyncRead + ?Sized,
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
[src]
R: AsyncRead,
fn read(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_to_string(&'a mut self, buf: &'a mut String) -> ReadToString<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>) where
Self: AsyncWrite,
[src]
Self: AsyncWrite,
fn take(self, limit: u64) -> Take<Self>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> BufReadExt for T where
T: AsyncBufRead + ?Sized,
[src]
T: AsyncBufRead + ?Sized,
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<'a, Self> where
Self: Unpin,
fn read_line(&'a mut self, buf: &'a mut String) -> ReadLineFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn lines(self) -> Lines<Self> where
Self: Unpin,
[src]
Self: Unpin,
fn split(self, byte: u8) -> Split<Self>
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ReadExt for T where
T: AsyncRead + ?Sized,
[src]
T: AsyncRead + ?Sized,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self> where
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEndFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
[src]
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self> where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self> where
Self: Unpin,
[src]
Self: Unpin,
fn take(self, limit: u64) -> Take<Self>
[src]
fn by_ref(&mut self) -> &mut Self
[src]
fn bytes(self) -> Bytes<Self>
[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
[src]
R: AsyncRead,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,