diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-22 09:56:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-22 09:56:08 -0800 |
commit | 9b2aa14bb185f552f0842319e7fbbfe0bd9b3dc6 (patch) | |
tree | 77aea8d87fc635275a76aec9cab015fa5d2cf743 | |
parent | 8546ff826db8dba1e39b4119ad909fb6cab2492a (diff) |
docs: annotate io mod with doc_cfg (#1808)
Annotates types in `tokio::io` module with their required feature flag.
This annotation is included in generated documentation.
Notes:
* The annotation must be on the type or function itself. Annotating just
the re-export is not sufficient.
* The annotation must be **inside** the `pin_project!` macro or it is
lost.
34 files changed, 768 insertions, 679 deletions
diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index fdec4695..320e5b38 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -126,3 +126,4 @@ tempfile = "3.1.0" [package.metadata.docs.rs] all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/tokio/src/io/poll_evented.rs b/tokio/src/io/poll_evented.rs index d1644ca2..bbd60259 100644 --- a/tokio/src/io/poll_evented.rs +++ b/tokio/src/io/poll_evented.rs @@ -10,98 +10,101 @@ use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering::Relaxed; use std::task::{Context, Poll}; -/// Associates an I/O resource that implements the [`std::io::Read`] and/or -/// [`std::io::Write`] traits with the reactor that drives it. -/// -/// `PollEvented` uses [`Registration`] internally to take a type that -/// implements [`mio::Evented`] as well as [`std::io::Read`] and or -/// [`std::io::Write`] and associate it with a reactor that will drive it. -/// -/// Once the [`mio::Evented`] type is wrapped by `PollEvented`, it can be -/// used from within the future's execution model. As such, the `PollEvented` -/// type provides [`AsyncRead`] and [`AsyncWrite`] implementations using the -/// underlying I/O resource as well as readiness events provided by the reactor. -/// -/// **Note**: While `PollEvented` is `Sync` (if the underlying I/O type is -/// `Sync`), the caller must ensure that there are at most two tasks that use a -/// `PollEvented` instance concurrently. One for reading and one for writing. -/// While violating this requirement is "safe" from a Rust memory model point of -/// view, it will result in unexpected behavior in the form of lost -/// notifications and tasks hanging. -/// -/// ## Readiness events -/// -/// Besides just providing [`AsyncRead`] and [`AsyncWrite`] implementations, -/// this type also supports access to the underlying readiness event stream. -/// While similar in function to what [`Registration`] provides, the semantics -/// are a bit different. -/// -/// Two functions are provided to access the readiness events: -/// [`poll_read_ready`] and [`poll_write_ready`]. These functions return the -/// current readiness state of the `PollEvented` instance. If -/// [`poll_read_ready`] indicates read readiness, immediately calling -/// [`poll_read_ready`] again will also indicate read readiness. -/// -/// When the operation is attempted and is unable to succeed due to the I/O -/// resource not being ready, the caller must call [`clear_read_ready`] or -/// [`clear_write_ready`]. This clears the readiness state until a new readiness -/// event is received. -/// -/// This allows the caller to implement additional functions. For example, -/// [`TcpListener`] implements poll_accept by using [`poll_read_ready`] and -/// [`clear_read_ready`]. -/// -/// ```rust -/// use tokio::io::PollEvented; -/// -/// use futures::ready; -/// use mio::Ready; -/// use mio::net::{TcpStream, TcpListener}; -/// use std::io; -/// use std::task::{Context, Poll}; -/// -/// struct MyListener { -/// poll_evented: PollEvented<TcpListener>, -/// } -/// -/// impl MyListener { -/// pub fn poll_accept(&mut self, cx: &mut Context<'_>) -> Poll<Result<TcpStream, io::Error>> { -/// let ready = Ready::readable(); -/// -/// ready!(self.poll_evented.poll_read_ready(cx, ready))?; -/// -/// match self.poll_evented.get_ref().accept() { -/// Ok((socket, _)) => Poll::Ready(Ok(socket)), -/// Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { -/// self.poll_evented.clear_read_ready(cx, ready)?; -/// Poll::Pending -/// } -/// Err(e) => Poll::Ready(Err(e)), -/// } -/// } -/// } -/// ``` -/// -/// ## Platform-specific events -/// -/// `PollEvented` also allows receiving platform-specific `mio::Ready` events. -/// These events are included as part of the read readiness event stream. The -/// write readiness event stream is only for `Ready::writable()` events. -/// -/// [`std::io::Read`]: https://doc.rust-lang.org/std/io/trait.Read.html -/// [`std::io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html -/// [`AsyncRead`]: ../io/trait.AsyncRead.html -/// [`AsyncWrite`]: ../io/trait.AsyncWrite.html -/// [`mio::Evented`]: https://docs.rs/mio/0.6/mio/trait.Evented.html -/// [`Registration`]: struct.Registration.html -/// [`TcpListener`]: ../net/struct.TcpListener.html -/// [`clear_read_ready`]: #method.clear_read_ready -/// [`clear_write_ready`]: #method.clear_write_ready -/// [`poll_read_ready`]: #method.poll_read_ready -/// [`poll_write_ready`]: #method.poll_write_ready -pub struct PollEvented<E: Evented> { - io: Option<E>, - inner: Inner, +cfg_io_driver! { + /// Associates an I/O resource that implements the [`std::io::Read`] and/or + /// [`std::io::Write`] traits with the reactor that drives it. + /// + /// `PollEvented` uses [`Registration`] internally to take a type that + /// implements [`mio::Evented`] as well as [`std::io::Read`] and or + /// [`std::io::Write`] and associate it with a reactor that will drive it. + /// + /// Once the [`mio::Evented`] type is wrapped by `PollEvented`, it can be + /// used from within the future's execution model. As such, the + /// `PollEvented` type provides [`AsyncRead`] and [`AsyncWrite`] + /// implementations using the underlying I/O resource as well as readiness + /// events provided by the reactor. + /// + /// **Note**: While `PollEvented` is `Sync` (if the underlying I/O type is + /// `Sync`), the caller must ensure that there are at most two tasks that + /// use a `PollEvented` instance concurrently. One for reading and one for + /// writing. While violating this requirement is "safe" from a Rust memory + /// model point of view, it will result in unexpected behavior in the form + /// of lost notifications and tasks hanging. + /// + /// ## Readiness events + /// + /// Besides just providing [`AsyncRead`] and [`AsyncWrite`] implementations, + /// this type also supports access to the underlying readiness event stream. + /// While similar in function to what [`Registration`] provides, the + /// semantics are a bit different. + /// + /// Two functions are provided to access the readiness events: + /// [`poll_read_ready`] and [`poll_write_ready`]. These functions return the + /// current readiness state of the `PollEvented` instance. If + /// [`poll_read_ready`] indicates read readiness, immediately calling + /// [`poll_read_ready`] again will also indicate read readiness. + /// + /// When the operation is attempted and is unable to succeed due to the I/O + /// resource not being ready, the caller must call [`clear_read_ready`] or + /// [`clear_write_ready`]. This clears the readiness state until a new + /// readiness event is received. + /// + /// This allows the caller to implement additional functions. For example, + /// [`TcpListener`] implements poll_accept by using [`poll_read_ready`] and + /// [`clear_read_ready`]. + /// + /// ```rust + /// use tokio::io::PollEvented; + /// + /// use futures::ready; + /// use mio::Ready; + /// use mio::net::{TcpStream, TcpListener}; + /// use std::io; + /// use std::task::{Context, Poll}; + /// + /// struct MyListener { + /// poll_evented: PollEvented<TcpListener>, + /// } + /// + /// impl MyListener { + /// pub fn poll_accept(&mut self, cx: &mut Context<'_>) -> Poll<Result<TcpStream, io::Error>> { + /// let ready = Ready::readable(); + /// + /// ready!(self.poll_evented.poll_read_ready(cx, ready))?; + /// + /// match self.poll_evented.get_ref().accept() { + /// Ok((socket, _)) => Poll::Ready(Ok(socket)), + /// Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { + /// self.poll_evented.clear_read_ready(cx, ready)?; + /// Poll::Pending + /// } + /// Err(e) => Poll::Ready(Err(e)), + /// } + /// } + /// } + /// ``` + /// + /// ## Platform-specific events + /// + /// `PollEvented` also allows receiving platform-specific `mio::Ready` events. + /// These events are included as part of the read readiness event stream. The + /// write readiness event stream is only for `Ready::writable()` events. + /// + /// [`std::io::Read`]: https://doc.rust-lang.org/std/io/trait.Read.html + /// [`std::io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html + /// [`AsyncRead`]: ../io/trait.AsyncRead.html + /// [`AsyncWrite`]: ../io/trait.AsyncWrite.html + /// [`mio::Evented`]: https://docs.rs/mio/0.6/mio/trait.Evented.html + /// [`Registration`]: struct.Registration.html + /// [`TcpListener`]: ../net/struct.TcpListener.html + /// [`clear_read_ready`]: #method.clear_read_ready + /// [`clear_write_ready`]: #method.clear_write_ready + /// [`poll_read_ready`]: #method.poll_read_ready + /// [`poll_write_ready`]: #method.poll_write_ready + pub struct PollEvented<E: Evented> { + io: Option<E>, + inner: Inner, + } } struct Inner { diff --git a/tokio/src/io/registration.rs b/tokio/src/io/registration.rs index 1a8db6d7..e8f9794d 100644 --- a/tokio/src/io/registration.rs +++ b/tokio/src/io/registration.rs @@ -5,40 +5,43 @@ use mio::{self, Evented}; use std::task::{Context, Poll}; use std::io; -/// Associates an I/O resource with the reactor instance that drives it. -/// -/// A registration represents an I/O resource registered with a Reactor such -/// that it will receive task notifications on readiness. This is the lowest -/// level API for integrating with a reactor. -/// -/// The association between an I/O resource is made by calling [`new`]. Once -/// the association is established, it remains established until the -/// registration instance is dropped. -/// -/// A registration instance represents two separate readiness streams. One for -/// the read readiness and one for write readiness. These streams are -/// independent and can be consumed from separate tasks. -/// -/// **Note**: while `Registration` is `Sync`, the caller must ensure that there -/// are at most two tasks that use a registration instance concurrently. One -/// task for [`poll_read_ready`] and one task for [`poll_write_ready`]. While -/// violating this requirement is "safe" from a Rust memory safety point of -/// view, it will result in unexpected behavior in the form of lost -/// notifications and tasks hanging. -/// -/// ## Platform-specific events -/// -/// `Registration` also allows receiving platform-specific `mio::Ready` events. -/// These events are included as part of the read readiness event stream. The -/// write readiness event stream is only for `Ready::writable()` events. -/// -/// [`new`]: #method.new -/// [`poll_read_ready`]: #method.poll_read_ready`] -/// [`poll_write_ready`]: #method.poll_write_ready`] -#[derive(Debug)] -pub struct Registration { - handle: Handle, - address: Address, +cfg_io_driver! { + /// Associates an I/O resource with the reactor instance that drives it. + /// + /// A registration represents an I/O resource registered with a Reactor such + /// that it will receive task notifications on readiness. This is the lowest + /// level API for integrating with a reactor. + /// + /// The association between an I/O resource is made by calling [`new`]. Once + /// the association is established, it remains established until the + /// registration instance is dropped. + /// + /// A registration instance represents two separate readiness streams. One + /// for the read readiness and one for write readiness. These streams are + /// independent and can be consumed from separate tasks. + /// + /// **Note**: while `Registration` is `Sync`, the caller must ensure that + /// there are at most two tasks that use a registration instance + /// concurrently. One task for [`poll_read_ready`] and one task for + /// [`poll_write_ready`]. While violating this requirement is "safe" from a + /// Rust memory safety point of view, it will result in unexpected behavior + /// in the form of lost notifications and tasks hanging. + /// + /// ## Platform-specific events + /// + /// `Registration` also allows receiving platform-specific `mio::Ready` + /// events. These events are included as part of the read readiness event + /// stream. The write readiness event stream is only for `Ready::writable()` + /// events. + /// + /// [`new`]: #method.new + /// [`poll_read_ready`]: #method.poll_read_ready`] + /// [`poll_write_ready`]: #method.poll_write_ready`] + #[derive(Debug)] + pub struct Registration { + handle: Handle, + address: Address, + } } // ===== impl Registration ===== diff --git a/tokio/src/io/split.rs b/tokio/src/io/split.rs index 388ee4ed..a01ceef2 100644 --- a/tokio/src/io/split.rs +++ b/tokio/src/io/split.rs @@ -16,14 +16,39 @@ use std::sync::atomic::Ordering::{Acquire, Release}; use std::sync::Arc; use std::task::{Context, Poll}; -/// The readable half of a value returned from `split`. -pub struct ReadHalf<T> { - inner: Arc<Inner<T>>, -} +cfg_io_util! { + /// The readable half of a value returned from `split`. + pub struct ReadHalf<T> { + inner: Arc<Inner<T>>, + } + + /// The writable half of a value returned from `split`. + pub struct WriteHalf<T> { + inner: Arc<Inner<T>>, + } -/// The writable half of a value returned from `split`. -pub struct WriteHalf<T> { - inner: Arc<Inner<T>>, + /// Split a single value implementing `AsyncRead + AsyncWrite` into separate + /// `AsyncRead` and `AsyncWrite` handles. + /// + /// To restore this read/write object from its `split::ReadHalf` and + /// `split::WriteHalf` use `unsplit`. + pub fn split<T>(stream: T) -> (ReadHalf<T>, WriteHalf<T>) + where + T: AsyncRead + AsyncWrite, + { + let inner = Arc::new(Inner { + locked: AtomicBool::new(false), + stream: UnsafeCell::new(stream), + }); + + let rd = ReadHalf { + inner: inner.clone(), + }; + + let wr = WriteHalf { inner }; + + (rd, wr) + } } struct Inner<T> { @@ -35,29 +60,6 @@ struct Guard<'a, T> { inner: &'a Inner<T>, } -/// Split a single value implementing `AsyncRead + AsyncWrite` into separate -/// `AsyncRead` and `AsyncWrite` handles. -/// -/// To restore this read/write object from its `split::ReadHalf` and -/// `split::WriteHalf` use `unsplit`. -pub fn split<T>(stream: T) -> (ReadHalf<T>, WriteHalf<T>) -where - T: AsyncRead + AsyncWrite, -{ - let inner = Arc::new(Inner { - locked: AtomicBool::new(false), - stream: UnsafeCell::new(stream), - }); - - let rd = ReadHalf { - inner: inner.clone(), - }; - - let wr = WriteHalf { inner }; - - (rd, wr) -} - impl<T> ReadHalf<T> { /// Reunite with a previously split `WriteHalf`. /// diff --git a/tokio/src/io/stderr.rs b/tokio/src/io/stderr.rs index 9e3f2e9b..231941f2 100644 --- a/tokio/src/io/stderr.rs +++ b/tokio/src/io/stderr.rs @@ -6,28 +6,30 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; -/// A handle to the standard error stream of a process. -/// -/// The handle implements the [`AsyncWrite`] trait, but beware that concurrent -/// writes to `Stderr` must be executed with care. -/// -/// Created by the [`stderr`] function. -/// -/// [`stderr`]: fn.stderr.html -/// [`AsyncWrite`]: trait.AsyncWrite.html -#[derive(Debug)] -pub struct Stderr { - std: Blocking<std::io::Stderr>, -} +cfg_io_std! { + /// A handle to the standard error stream of a process. + /// + /// The handle implements the [`AsyncWrite`] trait, but beware that concurrent + /// writes to `Stderr` must be executed with care. + /// + /// Created by the [`stderr`] function. + /// + /// [`stderr`]: fn.stderr.html + /// [`AsyncWrite`]: trait.AsyncWrite.html + #[derive(Debug)] + pub struct Stderr { + std: Blocking<std::io::Stderr>, + } -/// Constructs a new handle to the standard error of the current process. -/// -/// The returned handle allows writing to standard error from the within the -/// Tokio runtime. -pub fn stderr() -> Stderr { - let std = io::stderr(); - Stderr { - std: Blocking::new(std), + /// Constructs a new handle to the standard error of the current process. + /// + /// The returned handle allows writing to standard error from the within the + /// Tokio runtime. + pub fn stderr() -> Stderr { + let std = io::stderr(); + Stderr { + std: Blocking::new(std), + } } } diff --git a/tokio/src/io/stdin.rs b/tokio/src/io/stdin.rs index 58b19082..81bc5abb 100644 --- a/tokio/src/io/stdin.rs +++ b/tokio/src/io/stdin.rs @@ -6,34 +6,36 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; -/// A handle to the standard input stream of a process. -/// -/// The handle implements the [`AsyncRead`] trait, but beware that concurrent -/// reads of `Stdin` must be executed with care. -/// -/// As an additional caveat, reading from the handle may block the calling -/// future indefinitely, if there is not enough data available. This makes this -/// handle unsuitable for use in any circumstance where immediate reaction to -/// available data is required, e.g. interactive use or when implementing a -/// subprocess driven by requests on the standard input. -/// -/// Created by the [`stdin`] function. -/// -/// [`stdin`]: fn.stdin.html -/// [`AsyncRead`]: trait.AsyncRead.html -#[derive(Debug)] -pub struct Stdin { - std: Blocking<std::io::Stdin>, -} +cfg_io_std! { + /// A handle to the standard input stream of a process. + /// + /// The handle implements the [`AsyncRead`] trait, but beware that concurrent + /// reads of `Stdin` must be executed with care. + /// + /// As an additional caveat, reading from the handle may block the calling + /// future indefinitely, if there is not enough data available. This makes this + /// handle unsuitable for use in any circumstance where immediate reaction to + /// available data is required, e.g. interactive use or when implementing a + /// subprocess driven by requests on the standard input. + /// + /// Created by the [`stdin`] function. + /// + /// [`stdin`]: fn.stdin.html + /// [`AsyncRead`]: trait.AsyncRead.html + #[derive(Debug)] + pub struct Stdin { + std: Blocking<std::io::Stdin>, + } -/// Constructs a new handle to the standard input of the current process. -/// -/// The returned handle allows reading from standard input from the within the -/// Tokio runtime. -pub fn stdin() -> Stdin { - let std = io::stdin(); - Stdin { - std: Blocking::new(std), + /// Constructs a new handle to the standard input of the current process. + /// + /// The returned handle allows reading from standard input from the within the + /// Tokio runtime. + pub fn stdin() -> Stdin { + let std = io::stdin(); + Stdin { + std: Blocking::new(std), + } } } diff --git a/tokio/src/io/stdout.rs b/tokio/src/io/stdout.rs index c06c7d38..86de1c58 100644 --- a/tokio/src/io/stdout.rs +++ b/tokio/src/io/stdout.rs @@ -6,28 +6,30 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; -/// A handle to the standard output stream of a process. -/// -/// The handle implements the [`AsyncWrite`] trait, but beware that concurrent -/// writes to `Stdout` must be executed with care. -/// -/// Created by the [`stdout`] function. -/// -/// [`stdout`]: fn.stdout.html -/// [`AsyncWrite`]: trait.AsyncWrite.html -#[derive(Debug)] -pub struct Stdout { - std: Blocking<std::io::Stdout>, -} +cfg_io_std! { + /// A handle to the standard output stream of a process. + /// + /// The handle implements the [`AsyncWrite`] trait, but beware that concurrent + /// writes to `Stdout` must be executed with care. + /// + /// Created by the [`stdout`] function. + /// + /// [`stdout`]: fn.stdout.html + /// [`AsyncWrite`]: trait.AsyncWrite.html + #[derive(Debug)] + pub struct Stdout { + std: Blocking<std::io::Stdout>, + } -/// Constructs a new handle to the standard output of the current process. -/// -/// The returned handle allows writing to standard out from the within the Tokio -/// runtime. -pub fn stdout() -> Stdout { - let std = io::stdout(); - Stdout { - std: Blocking::new(std), + /// Constructs a new handle to the standard output of the current process. + /// + /// The returned handle allows writing to standard out from the within the Tokio + /// runtime. + pub fn stdout() -> Stdout { + let std = io::stdout(); + Stdout { + std: Blocking::new(std), + } } } diff --git a/tokio/src/io/util/async_buf_read_ext.rs b/tokio/src/io/util/async_buf_read_ext.rs index 7567d72e..86d09dd3 100644 --- a/tokio/src/io/util/async_buf_read_ext.rs +++ b/tokio/src/io/util/async_buf_read_ext.rs @@ -4,118 +4,120 @@ use crate::io::util::read_until::{read_until, ReadUntil}; use crate::io::util::split::{split, Split}; use crate::io::AsyncBufRead; -/// An extension trait which adds utility methods to `AsyncBufRead` types. -pub trait AsyncBufReadExt: AsyncBufRead { - /// Creates a future which will read all the bytes associated with this I/O - /// object into `buf` until the delimiter `byte` or EOF is reached. - /// This method is the async equivalent to [`BufRead::read_until`](std::io::BufRead::read_until). - /// - /// This function will read bytes from the underlying stream until the - /// delimiter or EOF is found. Once found, all bytes up to, and including, - /// the delimiter (if found) will be appended to `buf`. - /// - /// The returned future will resolve to the number of bytes read once the read - /// operation is completed. - /// - /// In the case of an error the buffer and the object will be discarded, with - /// the error yielded. - fn read_until<'a>(&'a mut self, byte: u8, buf: &'a mut Vec<u8>) -> ReadUntil<'a, Self> - where - Self: Unpin, - { - read_until(self, byte, buf) - } +cfg_io_util! { + /// An extension trait which adds utility methods to `AsyncBufRead` types. + pub trait AsyncBufReadExt: AsyncBufRead { + /// Creates a future which will read all the bytes associated with this I/O + /// object into `buf` until the delimiter `byte` or EOF is reached. + /// This method is the async equivalent to [`BufRead::read_until`](std::io::BufRead::read_until). + /// + /// This function will read bytes from the underlying stream until the + /// delimiter or EOF is found. Once found, all bytes up to, and including, + /// the delimiter (if found) will be appended to `buf`. + /// + /// The returned future will resolve to the number of bytes read once the read + /// operation is completed. + /// + /// In the case of an error the buffer and the object will be discarded, with + /// the error yielded. + fn read_until<'a>(&'a mut self, byte: u8, buf: &'a mut Vec<u8>) -> ReadUntil<'a, Self> + where + Self: Unpin, + { + read_until(self, byte, buf) + } - /// Creates a future which will read all the bytes associated with this I/O - /// object into `buf` until a newline (the 0xA byte) or EOF is reached, - /// This method is the async equivalent to [`BufRead::read_line`](std::io::BufRead::read_line). - /// - /// This function will read bytes from the underlying stream until the - /// newline delimiter (the 0xA byte) or EOF is found. Once found, all bytes - /// up to, and including, the delimiter (if found) will be appended to - /// `buf`. - /// - /// The returned future will resolve to the number of bytes read once the read - /// operation is completed. - /// - /// In the case of an error the buffer and the object will be discarded, with - /// the error yielded. - /// - /// # Errors - /// - /// This function has the same error semantics as [`read_until`] and will - /// also return an error if the read bytes are not valid UTF-8. If an I/O - /// error is encountered then `buf` may contain some bytes already read in - /// the event that all data read so far was valid UTF-8. - /// - /// [`read_until`]: AsyncBufReadExt::read_until - fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self> - where - Self: Unpin, - { - read_line(self, buf) - } + /// Creates a future which will read all the bytes associated with this I/O + /// object into `buf` until a newline (the 0xA byte) or EOF is reached, + /// This method is the async equivalent to [`BufRead::read_line`](std::io::BufRead::read_line). + /// + /// This function will read bytes from the underlying stream until the + /// newline delimiter (the 0xA byte) or EOF is found. Once found, all bytes + /// up to, and including, the delimiter (if found) will be appended to + /// `buf`. + /// + /// The returned future will resolve to the number of bytes read once the read + /// operation is completed. + /// + /// In the case of an error the buffer and the object will be discarded, with + /// the error yielded. + /// + /// # Errors + /// + /// This function has the same error semantics as [`read_until`] and will + /// also return an error if the read bytes are not valid UTF-8. If an I/O + /// error is encountered then `buf` may contain some bytes already read in + /// the event that all data read so far was valid UTF-8. + /// + /// [`read_until`]: AsyncBufReadExt::read_until + fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self> + where + Self: Unpin, + { + read_line(self, buf) + } - /// Returns a stream of the contents of this reader split on the byte - /// `byte`. - /// - /// This method is the asynchronous 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). - /// - /// # Examples - /// - /// ``` - /// # use tokio::io::AsyncBufRead; - /// use tokio::io::AsyncBufReadExt; - /// - /// # async fn dox(my_buf_read: impl AsyncBufRead + Unpin) -> std::io::Result<()> { - /// let mut segments = my_buf_read.split(b'f'); - /// - /// while let Some(segment) = segments.next_segment().await? { - /// println!("length = {}", segment.len()) - /// } - /// # Ok(()) - /// # } - /// ``` - fn split(self, byte: u8) -> Split<Self> - where - Self: Sized + Unpin, - { - split(self, byte) - } + /// Returns a stream of the contents of this reader split on the byte + /// `byte`. + /// + /// This method is the asynchronous 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). + /// + /// # Examples< |