diff options
author | Carl Lerche <me@carllerche.com> | 2020-10-12 16:06:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 16:06:02 -0700 |
commit | 19233508806ddf22a14acf944426e0da8a401df8 (patch) | |
tree | 5a204c0958ecc30f6ef05a464fb5446b398a7e46 /tokio/src/net | |
parent | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 (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.
Diffstat (limited to 'tokio/src/net')
-rw-r--r-- | tokio/src/net/addr.rs | 19 | ||||
-rw-r--r-- | tokio/src/net/lookup_host.rs | 2 | ||||
-rw-r--r-- | tokio/src/net/mod.rs | 4 | ||||
-rw-r--r-- | tokio/src/net/tcp/listener.rs | 21 | ||||
-rw-r--r-- | tokio/src/net/tcp/stream.rs | 22 |
5 files changed, 14 insertions, 54 deletions
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 |