mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
io: add AsyncBufReadExt::split (#1642)
add a `split` method to `AsyncBufReadExt`, analogous to `std::io::BufRead::split`.
This commit is contained in:
committed by
Carl Lerche
parent
b8913ec7c0
commit
69fe65e972
@@ -1,6 +1,7 @@
|
||||
use crate::io::lines::{lines, Lines};
|
||||
use crate::io::read_line::{read_line, ReadLine};
|
||||
use crate::io::read_until::{read_until, ReadUntil};
|
||||
use crate::io::split::{split, Split};
|
||||
use crate::AsyncBufRead;
|
||||
|
||||
/// An extension trait which adds utility methods to `AsyncBufRead` types.
|
||||
@@ -55,6 +56,30 @@ pub trait AsyncBufReadExt: AsyncBufRead {
|
||||
read_line(self, buf)
|
||||
}
|
||||
|
||||
/// Returns a stream of the contents of this reader split on the byte
|
||||
/// `byte`.
|
||||
///
|
||||
/// This method is the async equivalent to
|
||||
/// [`BufRead::split`](std::io::BufRead::split).
|
||||
///
|
||||
/// The stream returned from this function will yield instances of
|
||||
/// [`io::Result`]`<`[`Vec<u8>`]`>`. Each vector returned will *not* have
|
||||
/// the delimiter byte at the end.
|
||||
///
|
||||
/// [`io::Result`]: std::io::Result
|
||||
/// [`Vec<u8>`]: std::vec::Vec
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Each item of the stream has the same error semantics as
|
||||
/// [`AsyncBufReadExt::read_until`](AsyncBufReadExt::read_until).
|
||||
fn split(self, byte: u8) -> Split<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
split(self, byte)
|
||||
}
|
||||
|
||||
/// Returns a stream over the lines of this reader.
|
||||
/// This method is the async equivalent to [`BufRead::lines`](std::io::BufRead::lines).
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user