@@ -189,9 +189,23 @@ impl ToSocketAddrs for (Ipv6Addr, u16) {
189189 }
190190}
191191
192- fn lookup_host ( host : & str , port : u16 ) -> io:: Result < vec:: IntoIter < SocketAddr > > {
193- let addrs = crate :: sys:: net:: lookup_host ( host, port) ?;
194- Ok ( Vec :: from_iter ( addrs) . into_iter ( ) )
192+ // Default implementation, this shouldn't be called directly by the function's
193+ // path in this module. Instead, use the platform-specific implementation
194+ // (which may be this one).
195+ //
196+ // allow(dead_code): This function is only used on some targets
197+ #[ allow( dead_code) ]
198+ pub ( crate ) fn lookup_host_string ( addr : & str ) -> io:: Result < impl Iterator < Item = SocketAddr > > {
199+ // Split the string by ':' and convert the second part to u16...
200+ let Some ( ( host, port_str) ) = addr. rsplit_once ( ':' ) else {
201+ return Err ( io:: const_error!( io:: ErrorKind :: InvalidInput , "invalid socket address" ) ) ;
202+ } ;
203+ let Ok ( port) = port_str. parse :: < u16 > ( ) else {
204+ return Err ( io:: const_error!( io:: ErrorKind :: InvalidInput , "invalid port value" ) ) ;
205+ } ;
206+
207+ // ... and make the system look up the host.
208+ crate :: sys:: net:: lookup_host ( host, port)
195209}
196210
197211#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -207,7 +221,7 @@ impl ToSocketAddrs for (&str, u16) {
207221 }
208222
209223 // Otherwise, make the system look it up.
210- lookup_host ( host, port)
224+ crate :: sys :: net :: lookup_host ( host, port) . map ( |addrs| Vec :: from_iter ( addrs ) . into_iter ( ) )
211225 }
212226}
213227
@@ -229,16 +243,8 @@ impl ToSocketAddrs for str {
229243 return Ok ( vec ! [ addr] . into_iter ( ) ) ;
230244 }
231245
232- // Otherwise, split the string by ':' and convert the second part to u16...
233- let Some ( ( host, port_str) ) = self . rsplit_once ( ':' ) else {
234- return Err ( io:: const_error!( io:: ErrorKind :: InvalidInput , "invalid socket address" ) ) ;
235- } ;
236- let Ok ( port) = port_str. parse :: < u16 > ( ) else {
237- return Err ( io:: const_error!( io:: ErrorKind :: InvalidInput , "invalid port value" ) ) ;
238- } ;
239-
240- // ... and make the system look up the host.
241- lookup_host ( host, port)
246+ // Otherwise, make the system look it up.
247+ crate :: sys:: net:: lookup_host_string ( self ) . map ( |addrs| Vec :: from_iter ( addrs) . into_iter ( ) )
242248 }
243249}
244250
0 commit comments