1- use crate :: future:: Future ;
2- use crate :: task:: blocking:: JoinHandle ;
3- use cfg_if:: cfg_if;
4- use futures:: future:: { ready, Ready } ;
51use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
6- pub use std:: net:: { SocketAddr , SocketAddrV4 , SocketAddrV6 } ;
2+ use std:: net:: { SocketAddr , SocketAddrV4 , SocketAddrV6 } ;
73use std:: pin:: Pin ;
84
5+ use cfg_if:: cfg_if;
6+ use futures:: future:: { ready, Ready } ;
7+
8+ use crate :: future:: Future ;
9+ use crate :: io;
10+ use crate :: task:: blocking;
11+ use crate :: task:: { Context , Poll } ;
12+
913cfg_if ! {
1014 if #[ cfg( feature = "docs" ) ] {
1115 #[ doc( hidden) ]
1216 pub struct ImplFuture <T >( std:: marker:: PhantomData <T >) ;
1317
1418 macro_rules! ret {
15- ( $f: tt, $i: ty) => ( ImplFuture <crate :: io:: Result <$i>>) ;
19+ ( $f: tt, $i: ty) => ( ImplFuture <io:: Result <$i>>) ;
1620 }
1721 } else {
1822 macro_rules! ret {
@@ -21,40 +25,35 @@ cfg_if! {
2125 }
2226}
2327
24- /// A trait for objects which can be converted or resolved to one or more
25- /// [`SocketAddr`] values.
28+ /// A trait for objects which can be converted or resolved to one or more [`SocketAddr`] values.
2629///
2730/// This trait is an async version of [`std::net::ToSocketAddrs`].
2831///
2932/// [`std::net::ToSocketAddrs`]: https://doc.rust-lang.org/std/net/trait.ToSocketAddrs.html
3033pub trait ToSocketAddrs {
31- /// Returned iterator over socket addresses which this type may correspond
32- /// to.
34+ /// Returned iterator over socket addresses which this type may correspond to.
3335 type Iter : Iterator < Item = SocketAddr > + Send ;
36+
3437 /// Converts this object to an iterator of resolved `SocketAddr`s.
3538 ///
36- /// The returned iterator may not actually yield any values depending on the
37- /// outcome of any resolution performed.
39+ /// The returned iterator may not actually yield any values depending on the outcome of any
40+ /// resolution performed.
3841 ///
39- /// Note that this function may block a backend thread while resolution is
40- /// performed.
42+ /// Note that this function may block a backend thread while resolution is performed.
4143 fn to_socket_addrs ( & self ) -> ret ! ( ToSocketAddrsFuture , Self :: Iter ) ;
4244}
4345
4446#[ doc( hidden) ]
4547#[ allow( missing_debug_implementations) ]
4648pub enum ToSocketAddrsFuture < I : Iterator < Item = SocketAddr > > {
47- Join ( JoinHandle < crate :: io:: Result < I > > ) ,
48- Ready ( Ready < crate :: io:: Result < I > > ) ,
49+ Join ( blocking :: JoinHandle < io:: Result < I > > ) ,
50+ Ready ( Ready < io:: Result < I > > ) ,
4951}
5052
5153impl < I : Iterator < Item = SocketAddr > > Future for ToSocketAddrsFuture < I > {
52- type Output = crate :: io:: Result < I > ;
54+ type Output = io:: Result < I > ;
5355
54- fn poll (
55- self : Pin < & mut Self > ,
56- cx : & mut crate :: task:: Context < ' _ > ,
57- ) -> crate :: task:: Poll < Self :: Output > {
56+ fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
5857 match self . get_mut ( ) {
5958 ToSocketAddrsFuture :: Join ( f) => Pin :: new ( & mut * f) . poll ( cx) ,
6059 ToSocketAddrsFuture :: Ready ( f) => Pin :: new ( & mut * f) . poll ( cx) ,
@@ -116,7 +115,7 @@ impl ToSocketAddrs for (&str, u16) {
116115 fn to_socket_addrs ( & self ) -> ret ! ( ToSocketAddrsFuture , Self :: Iter ) {
117116 let host = self . 0 . to_string ( ) ;
118117 let port = self . 1 ;
119- let join = crate :: task :: blocking:: spawn ( async move {
118+ let join = blocking:: spawn ( async move {
120119 std:: net:: ToSocketAddrs :: to_socket_addrs ( & ( host. as_str ( ) , port) )
121120 } ) ;
122121 ToSocketAddrsFuture :: Join ( join)
@@ -128,9 +127,8 @@ impl ToSocketAddrs for str {
128127
129128 fn to_socket_addrs ( & self ) -> ret ! ( ToSocketAddrsFuture , Self :: Iter ) {
130129 let socket_addrs = self . to_string ( ) ;
131- let join = crate :: task:: blocking:: spawn ( async move {
132- std:: net:: ToSocketAddrs :: to_socket_addrs ( & socket_addrs)
133- } ) ;
130+ let join =
131+ blocking:: spawn ( async move { std:: net:: ToSocketAddrs :: to_socket_addrs ( & socket_addrs) } ) ;
134132 ToSocketAddrsFuture :: Join ( join)
135133 }
136134}
0 commit comments