summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-10-12 16:06:02 -0700
committerGitHub <noreply@github.com>2020-10-12 16:06:02 -0700
commit19233508806ddf22a14acf944426e0da8a401df8 (patch)
tree5a204c0958ecc30f6ef05a464fb5446b398a7e46
parentc90681bd8e629b5fde988b9f5be7b915e5cf8ae5 (diff)
meta: combine `net` and `dns`, use `parking_lot` (#2951)
This combines the `dns` and `net` feature flags. Previously, `dns` was included as part of `net`. Given that is is rare that one would want `dns` without `net`, DNS is now entirely gated w/ `net`. The `parking_lot` feature is included as part of `full`. Some misc docs are tweaked to reflect feature flag changes.
-rw-r--r--tokio/Cargo.toml4
-rw-r--r--tokio/src/lib.rs94
-rw-r--r--tokio/src/macros/cfg.rs13
-rw-r--r--tokio/src/net/addr.rs19
-rw-r--r--tokio/src/net/lookup_host.rs2
-rw-r--r--tokio/src/net/mod.rs4
-rw-r--r--tokio/src/net/tcp/listener.rs21
-rw-r--r--tokio/src/net/tcp/stream.rs22
8 files changed, 62 insertions, 117 deletions
diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml
index 6b0c4d8c..53aa41e1 100644
--- a/tokio/Cargo.toml
+++ b/tokio/Cargo.toml
@@ -30,12 +30,12 @@ default = []
# enable everything
full = [
- "dns",
"fs",
"io-util",
"io-std",
"macros",
"net",
+ "parking_lot",
"process",
"rt",
"rt-multi-thread",
@@ -45,14 +45,12 @@ full = [
"time",
]
-dns = []
fs = []
io-util = ["memchr"]
# stdin, stdout, stderr
io-std = []
macros = ["tokio-macros"]
net = [
- "dns",
"lazy_static",
"libc",
"mio/os-poll",
diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs
index 483f13ed..9d1e0e28 100644
--- a/tokio/src/lib.rs
+++ b/tokio/src/lib.rs
@@ -17,7 +17,7 @@
))]
#![cfg_attr(docsrs, feature(doc_cfg))]
-//! A runtime for writing reliable, asynchronous, and slim applications.
+//! A runtime for writing reliable network applications without compromising speed.
//!
//! Tokio is an event-driven, non-blocking I/O platform for writing asynchronous
//! applications with the Rust programming language. At a high level, it
@@ -60,52 +60,6 @@
//! tokio = { version = "0.2", features = ["full"] }
//! ```
//!
-//! ## Feature flags
-//!
-//! Tokio uses a set of [feature flags] to reduce the amount of compiled code. It
-//! is possible to just enable certain features over others. By default, Tokio
-//! does not enable any features but allows one to enable a subset for their use
-//! case. Below is a list of the available feature flags. You may also notice
-//! above each function, struct and trait there is listed one or more feature flags
-//! that are required for that item to be used. If you are new to Tokio it is
-//! recommended that you use the `full` feature flag which will enable all public APIs.
-//! Beware though that this will pull in many extra dependencies that you may not
-//! need.
-//!
-//! - `full`: Enables all Tokio public API features listed below.
-//! - `rt-core`: Enables `tokio::spawn`, the basic (current thread) scheduler,
-//! and non-scheduler utilities.
-//! - `rt-multi-thread`: Enables the heavier, multi-threaded, work-stealing scheduler.
-//! - `io-util`: Enables the IO based `Ext` traits.
-//! - `io-std`: Enable `Stdout`, `Stdin` and `Stderr` types.
-//! - `net`: Enables `tokio::net` types such as `TcpStream`, `UnixStream` and `UdpSocket`.
-//! - `time`: Enables `tokio::time` types and allows the schedulers to enable
-//! the built in timer.
-//! - `process`: Enables `tokio::process` types.
-//! - `macros`: Enables `#[tokio::main]` and `#[tokio::test]` macros.
-//! - `sync`: Enables all `tokio::sync` types.
-//! - `stream`: Enables optional `Stream` implementations for types within Tokio.
-//! - `signal`: Enables all `tokio::signal` types.
-//! - `fs`: Enables `tokio::fs` types.
-//! - `dns`: Enables async `tokio::net::ToSocketAddrs`.
-//! - `test-util`: Enables testing based infrastructure for the Tokio runtime.
-//! - `blocking`: Enables `block_in_place` and `spawn_blocking`.
-//!
-//! _Note: `AsyncRead` and `AsyncWrite` traits do not require any features and are
-//! always available._
-//!
-//! ### Internal features
-//!
-//! These features do not expose any new API, but influence internal
-//! implementation aspects of Tokio, and can pull in additional
-//! dependencies. They are not included in `full`:
-//!
-//! - `parking_lot`: As a potential optimization, use the _parking_lot_ crate's
-//! synchronization primitives internally. MSRV may increase according to the
-//! _parking_lot_ release in use.
-//!
-//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
-//!
//! ### Authoring applications
//!
//! Tokio is great for writing applications and most users in this case shouldn't
@@ -332,6 +286,50 @@
//! }
//! }
//! ```
+//!
+//! ## Feature flags
+//!
+//! Tokio uses a set of [feature flags] to reduce the amount of compiled code. It
+//! is possible to just enable certain features over others. By default, Tokio
+//! does not enable any features but allows one to enable a subset for their use
+//! case. Below is a list of the available feature flags. You may also notice
+//! above each function, struct and trait there is listed one or more feature flags
+//! that are required for that item to be used. If you are new to Tokio it is
+//! recommended that you use the `full` feature flag which will enable all public APIs.
+//! Beware though that this will pull in many extra dependencies that you may not
+//! need.
+//!
+//! - `full`: Enables all Tokio public API features listed below.
+//! - `rt`: Enables `tokio::spawn`, the basic (current thread) scheduler,
+//! and non-scheduler utilities.
+//! - `rt-multi-thread`: Enables the heavier, multi-threaded, work-stealing scheduler.
+//! - `io-util`: Enables the IO based `Ext` traits.
+//! - `io-std`: Enable `Stdout`, `Stdin` and `Stderr` types.
+//! - `net`: Enables `tokio::net` types such as `TcpStream`, `UnixStream` and `UdpSocket`.
+//! - `time`: Enables `tokio::time` types and allows the schedulers to enable
+//! the built in timer.
+//! - `process`: Enables `tokio::process` types.
+//! - `macros`: Enables `#[tokio::main]` and `#[tokio::test]` macros.
+//! - `sync`: Enables all `tokio::sync` types.
+//! - `stream`: Enables optional `Stream` implementations for types within Tokio.
+//! - `signal`: Enables all `tokio::signal` types.
+//! - `fs`: Enables `tokio::fs` types.
+//! - `test-util`: Enables testing based infrastructure for the Tokio runtime.
+//!
+//! _Note: `AsyncRead` and `AsyncWrite` traits do not require any features and are
+//! always available._
+//!
+//! ### Internal features
+//!
+//! These features do not expose any new API, but influence internal
+//! implementation aspects of Tokio, and can pull in additional
+//! dependencies.
+//!
+//! - `parking_lot`: As a potential optimization, use the _parking_lot_ crate's
+//! synchronization primitives internally. MSRV may increase according to the
+//! _parking_lot_ release in use.
+//!
+//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
// Includes re-exports used by macros.
//
@@ -359,7 +357,7 @@ cfg_process! {
pub mod process;
}
-#[cfg(any(feature = "dns", feature = "fs", feature = "io-std"))]
+#[cfg(any(feature = "net", feature = "fs", feature = "io-std"))]
mod blocking;
cfg_rt! {
diff --git a/tokio/src/macros/cfg.rs b/tokio/src/macros/cfg.rs
index fedef7ad..27929119 100644
--- a/tokio/src/macros/cfg.rs
+++ b/tokio/src/macros/cfg.rs
@@ -6,7 +6,7 @@ macro_rules! cfg_block_on {
$(
#[cfg(any(
feature = "fs",
- feature = "dns",
+ feature = "net",
feature = "io-std",
feature = "rt",
))]
@@ -32,16 +32,6 @@ macro_rules! cfg_atomic_waker_impl {
}
}
-macro_rules! cfg_dns {
- ($($item:item)*) => {
- $(
- #[cfg(feature = "dns")]
- #[cfg_attr(docsrs, doc(cfg(feature = "dns")))]
- $item
- )*
- }
-}
-
macro_rules! cfg_fs {
($($item:item)*) => {
$(
@@ -338,7 +328,6 @@ macro_rules! cfg_coop {
($($item:item)*) => {
$(
#[cfg(any(
- feature = "dns",
feature = "fs",
feature = "io-std",
feature = "net",
diff --git a/tokio/src/net/addr.rs b/tokio/src/net/addr.rs
index 86ae9919..7cbe531b 100644
--- a/tokio/src/net/addr.rs
+++ b/tokio/src/net/addr.rs
@@ -9,7 +9,7 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV
///
/// Implementations of `ToSocketAddrs` for string types require a DNS lookup.
/// These implementations are only provided when Tokio is used with the
-/// **`dns`** feature flag.
+/// **`net`** feature flag.
///
/// # Calling
///
@@ -23,12 +23,13 @@ pub trait ToSocketAddrs: sealed::ToSocketAddrsPriv {}
type ReadyFuture<T> = future::Ready<io::Result<T>>;
-#[cfg(any(feature = "dns", feature = "net"))]
-pub(crate) fn to_socket_addrs<T>(arg: T) -> T::Future
-where
- T: ToSocketAddrs,
-{
- arg.to_socket_addrs(sealed::Internal)
+cfg_net! {
+ pub(crate) fn to_socket_addrs<T>(arg: T) -> T::Future
+ where
+ T: ToSocketAddrs,
+ {
+ arg.to_socket_addrs(sealed::Internal)
+ }
}
// ===== impl &impl ToSocketAddrs =====
@@ -143,7 +144,7 @@ impl sealed::ToSocketAddrsPriv for &[SocketAddr] {
}
}
-cfg_dns! {
+cfg_net! {
// ===== impl str =====
impl ToSocketAddrs for str {}
@@ -256,7 +257,7 @@ pub(crate) mod sealed {
#[allow(missing_debug_implementations)]
pub struct Internal;
- cfg_dns! {
+ cfg_net! {
use crate::blocking::JoinHandle;
use std::option;
diff --git a/tokio/src/net/lookup_host.rs b/tokio/src/net/lookup_host.rs
index 150228b5..28861849 100644
--- a/tokio/src/net/lookup_host.rs
+++ b/tokio/src/net/lookup_host.rs
@@ -1,4 +1,4 @@
-cfg_dns! {
+cfg_net! {
use crate::net::addr::{self, ToSocketAddrs};
use std::io;
diff --git a/tokio/src/net/mod.rs b/tokio/src/net/mod.rs
index f355356f..b7365e6d 100644
--- a/tokio/src/net/mod.rs
+++ b/tokio/src/net/mod.rs
@@ -27,12 +27,10 @@ mod addr;
pub(crate) use addr::to_socket_addrs;
pub use addr::ToSocketAddrs;
-cfg_dns! {
+cfg_net! {
mod lookup_host;
pub use lookup_host::lookup_host;
-}
-cfg_net! {
pub mod tcp;
pub use tcp::listener::TcpListener;
pub use tcp::socket::TcpSocket;
diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs
index 57500615..d3323ae0 100644
--- a/tokio/src/net/tcp/listener.rs
+++ b/tokio/src/net/tcp/listener.rs
@@ -80,7 +80,7 @@ impl TcpListener {
/// method.
///
/// The address type can be any implementor of the [`ToSocketAddrs`] trait.
- /// Note that strings only implement this trait when the **`dns`** feature
+ /// Note that strings only implement this trait when the **`net`** feature
/// is enabled, as strings may contain domain names that need to be resolved.
///
/// If `addr` yields multiple addresses, bind will be attempted with each of
@@ -109,25 +109,6 @@ impl TcpListener {
/// Ok(())
/// }
/// ```
- ///
- /// Without the `dns` feature:
- ///
- /// ```no_run
- /// use tokio::net::TcpListener;
- /// use std::net::Ipv4Addr;
- ///
- /// use std::io;
- ///
- /// #[tokio::main]
- /// async fn main() -> io::Result<()> {
- /// let listener = TcpListener::bind((Ipv4Addr::new(127, 0, 0, 1), 2345)).await?;
- ///
- /// // use the listener
- ///
- /// # let _ = listener;
- /// Ok(())
- /// }
- /// ```
pub async fn bind<A: ToSocketAddrs>(addr: A) -> io::Result<TcpListener> {
let addrs = to_socket_addrs(addr).await?;
diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs
index 7acab7db..f90e9a39 100644
--- a/tokio/src/net/tcp/stream.rs
+++ b/tokio/src/net/tcp/stream.rs
@@ -61,7 +61,7 @@ impl TcpStream {
///
/// `addr` is an address of the remote host. Anything which implements the
/// [`ToSocketAddrs`] trait can be supplied as the address. Note that
- /// strings only implement this trait when the **`dns`** feature is enabled,
+ /// strings only implement this trait when the **`net`** feature is enabled,
/// as strings may contain domain names that need to be resolved.
///
/// If `addr` yields multiple addresses, connect will be attempted with each
@@ -90,26 +90,6 @@ impl TcpStream {
/// }
/// ```
///
- /// Without the `dns` feature:
- ///
- /// ```no_run
- /// use tokio::net::TcpStream;
- /// use tokio::prelude::*;
- /// use std::error::Error;
- /// use std::net::Ipv4Addr;
- ///
- /// #[tokio::main]
- /// async fn main() -> Result<(), Box<dyn Error>> {
- /// // Connect to a peer
- /// let mut stream = TcpStream::connect((Ipv4Addr::new(127, 0, 0, 1), 8080)).await?;
- ///
- /// // Write some data.
- /// stream.write_all(b"hello world!").await?;
- ///
- /// Ok(())
- /// }
- /// ```
- ///
/// The [`write_all`] method is defined on the [`AsyncWriteExt`] trait.
///
/// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all