diff --git a/src/net/addr.rs b/src/net/addr.rs index c3e3ac9..5cbc691 100644 --- a/src/net/addr.rs +++ b/src/net/addr.rs @@ -1,18 +1,22 @@ -use crate::future::Future; -use crate::task::blocking::JoinHandle; -use cfg_if::cfg_if; -use futures::future::{ready, Ready}; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; -pub use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; +use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; use std::pin::Pin; +use cfg_if::cfg_if; +use futures::future::{ready, Ready}; + +use crate::future::Future; +use crate::io; +use crate::task::blocking; +use crate::task::{Context, Poll}; + cfg_if! { if #[cfg(feature = "docs")] { #[doc(hidden)] pub struct ImplFuture(std::marker::PhantomData); macro_rules! ret { - ($f:tt, $i:ty) => (ImplFuture>); + ($f:tt, $i:ty) => (ImplFuture>); } } else { macro_rules! ret { @@ -21,40 +25,35 @@ cfg_if! { } } -/// A trait for objects which can be converted or resolved to one or more -/// [`SocketAddr`] values. +/// A trait for objects which can be converted or resolved to one or more [`SocketAddr`] values. /// /// This trait is an async version of [`std::net::ToSocketAddrs`]. /// /// [`std::net::ToSocketAddrs`]: https://doc.rust-lang.org/std/net/trait.ToSocketAddrs.html pub trait ToSocketAddrs { - /// Returned iterator over socket addresses which this type may correspond - /// to. + /// Returned iterator over socket addresses which this type may correspond to. type Iter: Iterator + Send; + /// Converts this object to an iterator of resolved `SocketAddr`s. /// - /// The returned iterator may not actually yield any values depending on the - /// outcome of any resolution performed. + /// The returned iterator may not actually yield any values depending on the outcome of any + /// resolution performed. /// - /// Note that this function may block a backend thread while resolution is - /// performed. + /// Note that this function may block a backend thread while resolution is performed. fn to_socket_addrs(&self) -> ret!(ToSocketAddrsFuture, Self::Iter); } #[doc(hidden)] #[allow(missing_debug_implementations)] pub enum ToSocketAddrsFuture> { - Join(JoinHandle>), - Ready(Ready>), + Join(blocking::JoinHandle>), + Ready(Ready>), } impl> Future for ToSocketAddrsFuture { - type Output = crate::io::Result; + type Output = io::Result; - fn poll( - self: Pin<&mut Self>, - cx: &mut crate::task::Context<'_>, - ) -> crate::task::Poll { + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { match self.get_mut() { ToSocketAddrsFuture::Join(f) => Pin::new(&mut *f).poll(cx), ToSocketAddrsFuture::Ready(f) => Pin::new(&mut *f).poll(cx), @@ -116,7 +115,7 @@ impl ToSocketAddrs for (&str, u16) { fn to_socket_addrs(&self) -> ret!(ToSocketAddrsFuture, Self::Iter) { let host = self.0.to_string(); let port = self.1; - let join = crate::task::blocking::spawn(async move { + let join = blocking::spawn(async move { std::net::ToSocketAddrs::to_socket_addrs(&(host.as_str(), port)) }); ToSocketAddrsFuture::Join(join) @@ -128,9 +127,8 @@ impl ToSocketAddrs for str { fn to_socket_addrs(&self) -> ret!(ToSocketAddrsFuture, Self::Iter) { let socket_addrs = self.to_string(); - let join = crate::task::blocking::spawn(async move { - std::net::ToSocketAddrs::to_socket_addrs(&socket_addrs) - }); + let join = + blocking::spawn(async move { std::net::ToSocketAddrs::to_socket_addrs(&socket_addrs) }); ToSocketAddrsFuture::Join(join) } } diff --git a/src/net/mod.rs b/src/net/mod.rs index 9d8ba52..9f4ef81 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -29,7 +29,9 @@ //! # }) } //! ``` -pub use addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs}; +pub use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; + +pub use addr::ToSocketAddrs; pub use tcp::{Incoming, TcpListener, TcpStream}; pub use udp::UdpSocket; diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index bbc4390..d41af8f 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -4,8 +4,8 @@ use cfg_if::cfg_if; use futures::future; use std::net::{Ipv4Addr, Ipv6Addr}; -use crate::net::addr::{SocketAddr, ToSocketAddrs}; use crate::net::driver::IoHandle; +use crate::net::{SocketAddr, ToSocketAddrs}; use crate::task::Poll; /// A UDP socket.