[−][src]Trait futures_lite::io::AsyncBufReadExt
Extension trait for AsyncBufRead
.
Provided methods
fn read_until<'a>(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<Self>ⓘImportant traits for ReadUntilFuture<'_, T>
impl<'_, T: AsyncBufRead + Unpin + ?Sized> Future for ReadUntilFuture<'_, T> type Output = Result<usize>;
where
Self: Unpin,
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<Self>ⓘ
Important traits for ReadUntilFuture<'_, T>
impl<'_, T: AsyncBufRead + Unpin + ?Sized> Future for ReadUntilFuture<'_, T> type Output = Result<usize>;
Self: Unpin,
Reads all bytes and appends them into buf
until the delimiter byte
or EOF is found.
This method will read bytes from the underlying stream until the delimiter or EOF is
found. All bytes up to and including the delimiter (if found) will be appended to buf
.
If successful, returns the total number of bytes read.
Examples
use futures_lite::*; let input: &[u8] = b"hello"; let mut reader = io::BufReader::new(input); let mut buf = Vec::new(); let n = reader.read_until(b'\n', &mut buf).await?;
fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLineFuture<Self>ⓘImportant traits for ReadLineFuture<'_, T>
impl<'_, T: AsyncBufRead + Unpin + ?Sized> Future for ReadLineFuture<'_, T> type Output = Result<usize>;
where
Self: Unpin,
Important traits for ReadLineFuture<'_, T>
impl<'_, T: AsyncBufRead + Unpin + ?Sized> Future for ReadLineFuture<'_, T> type Output = Result<usize>;
Self: Unpin,
Reads all bytes and appends them into buf
until a newline (the 0xA byte) or EOF is found.
This method will read bytes from the underlying stream until the newline delimiter (the
0xA byte) or EOF is found. All bytes up to, and including, the newline delimiter (if found)
will be appended to buf
.
If successful, returns the total number of bytes read.
Examples
use futures_lite::*; let input: &[u8] = b"hello"; let mut reader = io::BufReader::new(input); let mut line = String::new(); let n = reader.read_line(&mut line).await?;
fn lines(self) -> Lines<Self> where
Self: Unpin + Sized,
Self: Unpin + Sized,
Returns a stream over the lines of this byte stream.
The stream returned from this method yields items of type
io::Result
<
String
>
.
Each string returned will not have a newline byte (the 0xA byte) or CRLF (0xD, 0xA bytes)
at the end.
Examples
use futures_lite::*; let input: &[u8] = b"hello\nworld\n"; let mut reader = io::BufReader::new(input); let mut lines = reader.lines(); let mut line = String::new(); while let Some(line) = lines.next().await { println!("{}", line?); }
fn split(self, byte: u8) -> Split<Self> where
Self: Sized,
Self: Sized,
Returns a stream over the contents of this reader split on the specified byte
.
The stream returned from this method yields items of type
io::Result
<
Vec<u8>
>
.
Each vector returned will not have the delimiter byte at the end.
Examples
use futures_lite::*; let cursor = io::Cursor::new(b"lorem-ipsum-dolor"); let items: Vec<Vec<u8>> = cursor.split(b'-').try_collect().await?; assert_eq!(items[0], b"lorem"); assert_eq!(items[1], b"ipsum"); assert_eq!(items[2], b"dolor");