tokio: remove prelude (#3299)

Closes: #3257
This commit is contained in:
Alice Ryhl
2020-12-19 11:42:24 -08:00
committed by GitHub
parent e41e6cddbb
commit 78f2340d25
26 changed files with 46 additions and 95 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ A basic TCP echo server with Tokio:
```rust,no_run
use tokio::net::TcpListener;
use tokio::prelude::*;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
+1 -1
View File
@@ -39,7 +39,7 @@
//! Specifically, given the following:
//!
//! ```
//! use tokio::prelude::*;
//! use tokio::io::{AsyncRead, AsyncWrite};
//! use tokio_util::codec::{Framed, LengthDelimitedCodec};
//!
//! use futures::SinkExt;
+1 -2
View File
@@ -1,6 +1,5 @@
#![warn(rust_2018_idioms)]
use tokio::prelude::*;
use tokio_stream::StreamExt;
use tokio_test::assert_ok;
use tokio_util::codec::{Decoder, Encoder, Framed, FramedParts};
@@ -52,7 +51,7 @@ impl Read for DontReadIntoThis {
}
}
impl AsyncRead for DontReadIntoThis {
impl tokio::io::AsyncRead for DontReadIntoThis {
fn poll_read(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
+1 -1
View File
@@ -55,7 +55,7 @@ A basic TCP echo server with Tokio:
```rust,no_run
use tokio::net::TcpListener;
use tokio::prelude::*;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
+8 -10
View File
@@ -37,8 +37,7 @@ use std::task::Poll::*;
/// the data to disk.
///
/// Reading and writing to a `File` is usually done using the convenience
/// methods found on the [`AsyncReadExt`] and [`AsyncWriteExt`] traits. Examples
/// import these traits through [the prelude].
/// methods found on the [`AsyncReadExt`] and [`AsyncWriteExt`] traits.
///
/// [std]: struct@std::fs::File
/// [`AsyncSeek`]: trait@crate::io::AsyncSeek
@@ -46,7 +45,6 @@ use std::task::Poll::*;
/// [`sync_all`]: fn@crate::fs::File::sync_all
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
/// [the prelude]: crate::prelude
///
/// # Examples
///
@@ -54,7 +52,7 @@ use std::task::Poll::*;
///
/// ```no_run
/// use tokio::fs::File;
/// use tokio::prelude::*; // for write_all()
/// use tokio::io::AsyncWriteExt; // for write_all()
///
/// # async fn dox() -> std::io::Result<()> {
/// let mut file = File::create("foo.txt").await?;
@@ -67,7 +65,7 @@ use std::task::Poll::*;
///
/// ```no_run
/// use tokio::fs::File;
/// use tokio::prelude::*; // for read_to_end()
/// use tokio::io::AsyncReadExt; // for read_to_end()
///
/// # async fn dox() -> std::io::Result<()> {
/// let mut file = File::open("foo.txt").await?;
@@ -125,7 +123,7 @@ impl File {
///
/// ```no_run
/// use tokio::fs::File;
/// use tokio::prelude::*;
/// use tokio::io::AsyncReadExt;
///
/// # async fn dox() -> std::io::Result<()> {
/// let mut file = File::open("foo.txt").await?;
@@ -169,7 +167,7 @@ impl File {
///
/// ```no_run
/// use tokio::fs::File;
/// use tokio::prelude::*;
/// use tokio::io::AsyncWriteExt;
///
/// # async fn dox() -> std::io::Result<()> {
/// let mut file = File::create("foo.txt").await?;
@@ -221,7 +219,7 @@ impl File {
///
/// ```no_run
/// use tokio::fs::File;
/// use tokio::prelude::*;
/// use tokio::io::AsyncWriteExt;
///
/// # async fn dox() -> std::io::Result<()> {
/// let mut file = File::create("foo.txt").await?;
@@ -256,7 +254,7 @@ impl File {
///
/// ```no_run
/// use tokio::fs::File;
/// use tokio::prelude::*;
/// use tokio::io::AsyncWriteExt;
///
/// # async fn dox() -> std::io::Result<()> {
/// let mut file = File::create("foo.txt").await?;
@@ -294,7 +292,7 @@ impl File {
///
/// ```no_run
/// use tokio::fs::File;
/// use tokio::prelude::*;
/// use tokio::io::AsyncWriteExt;
///
/// # async fn dox() -> std::io::Result<()> {
/// let mut file = File::create("foo.txt").await?;
+1 -4
View File
@@ -39,11 +39,9 @@ cfg_io_util! {
/// [`AsyncRead`] types. Callers will tend to import this trait instead of
/// [`AsyncRead`].
///
/// As a convenience, this trait may be imported using the [`prelude`]:
///
/// ```no_run
/// use tokio::fs::File;
/// use tokio::prelude::*;
/// use tokio::io::{self, AsyncReadExt};
///
/// #[tokio::main]
/// async fn main() -> io::Result<()> {
@@ -60,7 +58,6 @@ cfg_io_util! {
/// See [module][crate::io] documentation for more details.
///
/// [`AsyncRead`]: AsyncRead
/// [`prelude`]: crate::prelude
pub trait AsyncReadExt: AsyncRead {
/// Creates a new `AsyncRead` instance that chains this stream with
/// `next`.
+4 -7
View File
@@ -3,15 +3,13 @@ use crate::io::AsyncSeek;
use std::io::SeekFrom;
cfg_io_util! {
/// An extension trait which adds utility methods to [`AsyncSeek`] types.
///
/// As a convenience, this trait may be imported using the [`prelude`]:
/// An extension trait that adds utility methods to [`AsyncSeek`] types.
///
/// # Examples
///
/// ```
/// use std::io::{Cursor, SeekFrom};
/// use tokio::prelude::*;
/// use std::io::{self, Cursor, SeekFrom};
/// use tokio::io::{AsyncSeekExt, AsyncReadExt};
///
/// #[tokio::main]
/// async fn main() -> io::Result<()> {
@@ -32,7 +30,6 @@ cfg_io_util! {
/// See [module][crate::io] documentation for more details.
///
/// [`AsyncSeek`]: AsyncSeek
/// [`prelude`]: crate::prelude
pub trait AsyncSeekExt: AsyncSeek {
/// Creates a future which will seek an IO object, and then yield the
/// new position in the object and the object itself.
@@ -50,7 +47,7 @@ cfg_io_util! {
///
/// ```no_run
/// use tokio::fs::File;
/// use tokio::prelude::*;
/// use tokio::io::{AsyncSeekExt, AsyncReadExt};
///
/// use std::io::SeekFrom;
///
+1 -4
View File
@@ -39,10 +39,8 @@ cfg_io_util! {
/// [`AsyncWrite`] types. Callers will tend to import this trait instead of
/// [`AsyncWrite`].
///
/// As a convenience, this trait may be imported using the [`prelude`]:
///
/// ```no_run
/// use tokio::prelude::*;
/// use tokio::io::{self, AsyncWriteExt};
/// use tokio::fs::File;
///
/// #[tokio::main]
@@ -64,7 +62,6 @@ cfg_io_util! {
/// See [module][crate::io] documentation for more details.
///
/// [`AsyncWrite`]: AsyncWrite
/// [`prelude`]: crate::prelude
pub trait AsyncWriteExt: AsyncWrite {
/// Writes a buffer into this writer, returning how many bytes were
/// written.
+1 -3
View File
@@ -254,7 +254,7 @@
//!
//! ```no_run
//! use tokio::net::TcpListener;
//! use tokio::prelude::*;
//! use tokio::io::{AsyncReadExt, AsyncWriteExt};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -363,8 +363,6 @@ pub mod net;
mod loom;
mod park;
pub mod prelude;
cfg_process! {
pub mod process;
}
+3 -5
View File
@@ -20,12 +20,11 @@ use std::task::{Context, Poll};
/// Borrowed read half of a [`TcpStream`], created by [`split`].
///
/// Reading from a `ReadHalf` is usually done using the convenience methods found on the
/// [`AsyncReadExt`] trait. Examples import this trait through [the prelude].
/// [`AsyncReadExt`] trait.
///
/// [`TcpStream`]: TcpStream
/// [`split`]: TcpStream::split()
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
/// [the prelude]: crate::prelude
#[derive(Debug)]
pub struct ReadHalf<'a>(&'a TcpStream);
@@ -35,14 +34,13 @@ pub struct ReadHalf<'a>(&'a TcpStream);
/// shut down the TCP stream in the write direction.
///
/// Writing to an `WriteHalf` is usually done using the convenience methods found
/// on the [`AsyncWriteExt`] trait. Examples import this trait through [the prelude].
/// on the [`AsyncWriteExt`] trait.
///
/// [`TcpStream`]: TcpStream
/// [`split`]: TcpStream::split()
/// [`AsyncWrite`]: trait@crate::io::AsyncWrite
/// [`poll_shutdown`]: fn@crate::io::AsyncWrite::poll_shutdown
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
/// [the prelude]: crate::prelude
#[derive(Debug)]
pub struct WriteHalf<'a>(&'a TcpStream);
@@ -101,7 +99,7 @@ impl ReadHalf<'_> {
///
/// ```no_run
/// use tokio::net::TcpStream;
/// use tokio::prelude::*;
/// use tokio::io::AsyncReadExt;
/// use std::error::Error;
///
/// #[tokio::main]
+3 -5
View File
@@ -22,12 +22,11 @@ use std::{fmt, io};
/// Owned read half of a [`TcpStream`], created by [`into_split`].
///
/// Reading from an `OwnedReadHalf` is usually done using the convenience methods found
/// on the [`AsyncReadExt`] trait. Examples import this trait through [the prelude].
/// on the [`AsyncReadExt`] trait.
///
/// [`TcpStream`]: TcpStream
/// [`into_split`]: TcpStream::into_split()
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
/// [the prelude]: crate::prelude
#[derive(Debug)]
pub struct OwnedReadHalf {
inner: Arc<TcpStream>,
@@ -40,14 +39,13 @@ pub struct OwnedReadHalf {
/// will also shut down the write half of the TCP stream.
///
/// Writing to an `OwnedWriteHalf` is usually done using the convenience methods found
/// on the [`AsyncWriteExt`] trait. Examples import this trait through [the prelude].
/// on the [`AsyncWriteExt`] trait.
///
/// [`TcpStream`]: TcpStream
/// [`into_split`]: TcpStream::into_split()
/// [`AsyncWrite`]: trait@crate::io::AsyncWrite
/// [`poll_shutdown`]: fn@crate::io::AsyncWrite::poll_shutdown
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
/// [the prelude]: crate::prelude
#[derive(Debug)]
pub struct OwnedWriteHalf {
inner: Arc<TcpStream>,
@@ -156,7 +154,7 @@ impl OwnedReadHalf {
///
/// ```no_run
/// use tokio::net::TcpStream;
/// use tokio::prelude::*;
/// use tokio::io::AsyncReadExt;
/// use std::error::Error;
///
/// #[tokio::main]
+4 -5
View File
@@ -25,20 +25,19 @@ cfg_net! {
///
/// Reading and writing to a `TcpStream` is usually done using the
/// convenience methods found on the [`AsyncReadExt`] and [`AsyncWriteExt`]
/// traits. Examples import these traits through [the prelude].
/// traits.
///
/// [`connect`]: method@TcpStream::connect
/// [accepting]: method@crate::net::TcpListener::accept
/// [listener]: struct@crate::net::TcpListener
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
/// [the prelude]: crate::prelude
///
/// # Examples
///
/// ```no_run
/// use tokio::net::TcpStream;
/// use tokio::prelude::*;
/// use tokio::io::AsyncWriteExt;
/// use std::error::Error;
///
/// #[tokio::main]
@@ -81,7 +80,7 @@ impl TcpStream {
///
/// ```no_run
/// use tokio::net::TcpStream;
/// use tokio::prelude::*;
/// use tokio::io::AsyncWriteExt;
/// use std::error::Error;
///
/// #[tokio::main]
@@ -648,7 +647,7 @@ impl TcpStream {
///
/// ```no_run
/// use tokio::net::TcpStream;
/// use tokio::prelude::*;
/// use tokio::io::AsyncReadExt;
/// use std::error::Error;
///
/// #[tokio::main]
+2 -4
View File
@@ -19,12 +19,11 @@ use std::task::{Context, Poll};
/// Borrowed read half of a [`UnixStream`], created by [`split`].
///
/// Reading from a `ReadHalf` is usually done using the convenience methods found on the
/// [`AsyncReadExt`] trait. Examples import this trait through [the prelude].
/// [`AsyncReadExt`] trait.
///
/// [`UnixStream`]: UnixStream
/// [`split`]: UnixStream::split()
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
/// [the prelude]: crate::prelude
#[derive(Debug)]
pub struct ReadHalf<'a>(&'a UnixStream);
@@ -34,14 +33,13 @@ pub struct ReadHalf<'a>(&'a UnixStream);
/// shut down the UnixStream stream in the write direction.
///
/// Writing to an `WriteHalf` is usually done using the convenience methods found
/// on the [`AsyncWriteExt`] trait. Examples import this trait through [the prelude].
/// on the [`AsyncWriteExt`] trait.
///
/// [`UnixStream`]: UnixStream
/// [`split`]: UnixStream::split()
/// [`AsyncWrite`]: trait@crate::io::AsyncWrite
/// [`poll_shutdown`]: fn@crate::io::AsyncWrite::poll_shutdown
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
/// [the prelude]: crate::prelude
#[derive(Debug)]
pub struct WriteHalf<'a>(&'a UnixStream);
+2 -5
View File
@@ -21,12 +21,11 @@ use std::{fmt, io};
/// Owned read half of a [`UnixStream`], created by [`into_split`].
///
/// Reading from an `OwnedReadHalf` is usually done using the convenience methods found
/// on the [`AsyncReadExt`] trait. Examples import this trait through [the prelude].
/// on the [`AsyncReadExt`] trait.
///
/// [`UnixStream`]: crate::net::UnixStream
/// [`into_split`]: crate::net::UnixStream::into_split()
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
/// [the prelude]: crate::prelude
#[derive(Debug)]
pub struct OwnedReadHalf {
inner: Arc<UnixStream>,
@@ -39,15 +38,13 @@ pub struct OwnedReadHalf {
/// Dropping the write half will also shut down the write half of the stream.
///
/// Writing to an `OwnedWriteHalf` is usually done using the convenience methods
/// found on the [`AsyncWriteExt`] trait. Examples import this trait through
/// [the prelude].
/// found on the [`AsyncWriteExt`] trait.
///
/// [`UnixStream`]: crate::net::UnixStream
/// [`into_split`]: crate::net::UnixStream::into_split()
/// [`AsyncWrite`]: trait@crate::io::AsyncWrite
/// [`poll_shutdown`]: fn@crate::io::AsyncWrite::poll_shutdown
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
/// [the prelude]: crate::prelude
#[derive(Debug)]
pub struct OwnedWriteHalf {
inner: Arc<UnixStream>,
-21
View File
@@ -1,21 +0,0 @@
#![cfg(not(loom))]
//! A "prelude" for users of the `tokio` crate.
//!
//! This prelude is similar to the standard library's prelude in that you'll
//! almost always want to import its entire contents, but unlike the standard
//! library's prelude you'll have to do so manually:
//!
//! ```
//! # #![allow(warnings)]
//! use tokio::prelude::*;
//! ```
//!
//! The prelude may grow over time as additional items see ubiquitous use.
pub use crate::io::{self, AsyncBufRead, AsyncRead, AsyncWrite};
cfg_io_util! {
#[doc(no_inline)]
pub use crate::io::{AsyncBufReadExt as _, AsyncReadExt as _, AsyncSeekExt as _, AsyncWriteExt as _};
}
+2 -2
View File
@@ -20,7 +20,7 @@
//!
//! ```no_run
//! use tokio::net::TcpListener;
//! use tokio::prelude::*;
//! use tokio::io::{AsyncReadExt, AsyncWriteExt};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -63,7 +63,7 @@
//!
//! ```no_run
//! use tokio::net::TcpListener;
//! use tokio::prelude::*;
//! use tokio::io::{AsyncReadExt, AsyncWriteExt};
//! use tokio::runtime::Runtime;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
+1 -3
View File
@@ -36,9 +36,7 @@
//! }
//! ```
//!
//! Require that an operation takes no more than 300ms. Note that this uses the
//! `timeout` function on the `FutureExt` trait. This trait is included in the
//! prelude.
//! Require that an operation takes no more than 300ms.
//!
//! ```
//! use tokio::time::{timeout, Duration};
+1 -2
View File
@@ -2,7 +2,6 @@
#![cfg(feature = "full")]
use tokio::net::TcpListener;
use tokio::prelude::*;
use tokio_test::assert_ok;
use std::io::prelude::*;
@@ -41,7 +40,7 @@ async fn echo_server() {
let (mut a, _) = assert_ok!(srv.accept().await);
let (mut b, _) = assert_ok!(srv.accept().await);
let n = assert_ok!(io::copy(&mut a, &mut b).await);
let n = assert_ok!(tokio::io::copy(&mut a, &mut b).await);
let (expected, t2) = t.join().unwrap();
let actual = t2.join().unwrap();
+1 -1
View File
@@ -2,7 +2,7 @@
#![cfg(feature = "full")]
use tokio::fs::File;
use tokio::prelude::*;
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
use tokio_test::task;
use std::io::prelude::*;
+1 -1
View File
@@ -62,7 +62,7 @@ pub(crate) mod sync {
}
use fs::sys;
use tokio::prelude::*;
use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
use tokio_test::{assert_pending, assert_ready, assert_ready_err, assert_ready_ok, task};
use std::io::SeekFrom;
+1 -1
View File
@@ -11,7 +11,7 @@
use std::process::Stdio;
use std::time::Duration;
use tokio::prelude::*;
use tokio::io::AsyncWriteExt;
use tokio::process::Command;
use tokio::time;
use tokio_test::assert_err;
+1 -1
View File
@@ -56,7 +56,7 @@ fn send_sync_bound() {
rt_test! {
use tokio::net::{TcpListener, TcpStream, UdpSocket};
use tokio::prelude::*;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::runtime::Runtime;
use tokio::sync::oneshot;
use tokio::{task, time};
+1 -1
View File
@@ -169,7 +169,7 @@ async fn connect_addr_host_str_port_tuple() {
#[cfg(target_os = "linux")]
mod linux {
use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::*;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio_test::assert_ok;
use mio::unix::UnixReady;
+1 -1
View File
@@ -1,8 +1,8 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::*;
use tokio::sync::oneshot;
use tokio_test::assert_ok;
+2 -3
View File
@@ -1,9 +1,8 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::io::{self, AsyncWriteExt};
use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
use tokio::prelude::*;
use tokio_test::assert_ok;
#[tokio::test]
@@ -16,7 +15,7 @@ async fn shutdown() {
assert_ok!(AsyncWriteExt::shutdown(&mut stream).await);
let mut buf = [0; 1];
let mut buf = [0u8; 1];
let n = assert_ok!(stream.read(&mut buf).await);
assert_eq!(n, 0);
});
+1 -1
View File
@@ -2,8 +2,8 @@
#![cfg(feature = "full")]
#![cfg(unix)]
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use tokio::net::UnixStream;
use tokio::prelude::*;
/// Checks that `UnixStream` can be split into a read half and a write half using
/// `UnixStream::split` and `UnixStream::split_mut`.