1010
1111use std:: fmt;
1212use std:: io:: { self , Read , Write } ;
13- use std:: net:: { self , SocketAddr , Ipv4Addr , Ipv6Addr , Shutdown } ;
13+ use std:: net:: { self , Ipv4Addr , Ipv6Addr , Shutdown } ;
1414use std:: time:: Duration ;
1515
1616#[ cfg( unix) ]
@@ -19,7 +19,7 @@ use libc as c;
1919use winapi as c;
2020
2121use sys;
22- use { Socket , Protocol , Domain , Type } ;
22+ use { Socket , Protocol , Domain , Type , SockAddr } ;
2323
2424impl Socket {
2525 /// Creates a new socket ready to be configured.
@@ -58,7 +58,7 @@ impl Socket {
5858 ///
5959 /// An error will be returned if `listen` or `connect` has already been
6060 /// called on this builder.
61- pub fn connect ( & self , addr : & SocketAddr ) -> io:: Result < ( ) > {
61+ pub fn connect ( & self , addr : & SockAddr ) -> io:: Result < ( ) > {
6262 self . inner . connect ( addr)
6363 }
6464
@@ -81,15 +81,15 @@ impl Socket {
8181 ///
8282 /// If the connection request times out, it may still be processing in the
8383 /// background - a second call to `connect` or `connect_timeout` may fail.
84- pub fn connect_timeout ( & self , addr : & SocketAddr , timeout : Duration ) -> io:: Result < ( ) > {
84+ pub fn connect_timeout ( & self , addr : & SockAddr , timeout : Duration ) -> io:: Result < ( ) > {
8585 self . inner . connect_timeout ( addr, timeout)
8686 }
8787
8888 /// Binds this socket to the specified address.
8989 ///
9090 /// This function directly corresponds to the bind(2) function on Windows
9191 /// and Unix.
92- pub fn bind ( & self , addr : & SocketAddr ) -> io:: Result < ( ) > {
92+ pub fn bind ( & self , addr : & SockAddr ) -> io:: Result < ( ) > {
9393 self . inner . bind ( addr)
9494 }
9595
@@ -110,19 +110,19 @@ impl Socket {
110110 /// This function will block the calling thread until a new connection is
111111 /// established. When established, the corresponding `Socket` and the
112112 /// remote peer's address will be returned.
113- pub fn accept ( & self ) -> io:: Result < ( Socket , SocketAddr ) > {
113+ pub fn accept ( & self ) -> io:: Result < ( Socket , SockAddr ) > {
114114 self . inner . accept ( ) . map ( |( socket, addr) | {
115115 ( Socket { inner : socket } , addr)
116116 } )
117117 }
118118
119119 /// Returns the socket address of the local half of this TCP connection.
120- pub fn local_addr ( & self ) -> io:: Result < SocketAddr > {
120+ pub fn local_addr ( & self ) -> io:: Result < SockAddr > {
121121 self . inner . local_addr ( )
122122 }
123123
124124 /// Returns the socket address of the remote peer of this TCP connection.
125- pub fn peer_addr ( & self ) -> io:: Result < SocketAddr > {
125+ pub fn peer_addr ( & self ) -> io:: Result < SockAddr > {
126126 self . inner . peer_addr ( )
127127 }
128128
@@ -184,7 +184,7 @@ impl Socket {
184184
185185 /// Receives data from the socket. On success, returns the number of bytes
186186 /// read and the address from whence the data came.
187- pub fn recv_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , SocketAddr ) > {
187+ pub fn recv_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , SockAddr ) > {
188188 self . inner . recv_from ( buf)
189189 }
190190
@@ -195,7 +195,7 @@ impl Socket {
195195 ///
196196 /// On success, returns the number of bytes peeked and the address from
197197 /// whence the data came.
198- pub fn peek_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , SocketAddr ) > {
198+ pub fn peek_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , SockAddr ) > {
199199 self . inner . peek_from ( buf)
200200 }
201201
@@ -214,7 +214,7 @@ impl Socket {
214214 ///
215215 /// This is typically used on UDP or datagram-oriented sockets. On success
216216 /// returns the number of bytes that were sent.
217- pub fn send_to ( & self , buf : & [ u8 ] , addr : & SocketAddr ) -> io:: Result < usize > {
217+ pub fn send_to ( & self , buf : & [ u8 ] , addr : & SockAddr ) -> io:: Result < usize > {
218218 self . inner . send_to ( buf, addr)
219219 }
220220
@@ -693,12 +693,14 @@ impl From<Protocol> for i32 {
693693
694694#[ cfg( test) ]
695695mod test {
696+ use std:: net:: SocketAddr ;
697+
696698 use super :: * ;
697699
698700 #[ test]
699701 fn connect_timeout_unrouteable ( ) {
700702 // this IP is unroutable, so connections should always time out
701- let addr: SocketAddr = "10.255.255.1:80" . parse ( ) . unwrap ( ) ;
703+ let addr = "10.255.255.1:80" . parse :: < SocketAddr > ( ) . unwrap ( ) . into ( ) ;
702704
703705 let socket = Socket :: new ( Domain :: ipv4 ( ) , Type :: stream ( ) , None ) . unwrap ( ) ;
704706 match socket. connect_timeout ( & addr, Duration :: from_millis ( 250 ) ) {
@@ -711,7 +713,7 @@ mod test {
711713 #[ test]
712714 fn connect_timeout_valid ( ) {
713715 let socket = Socket :: new ( Domain :: ipv4 ( ) , Type :: stream ( ) , None ) . unwrap ( ) ;
714- socket. bind ( & "127.0.0.1:0" . parse ( ) . unwrap ( ) ) . unwrap ( ) ;
716+ socket. bind ( & "127.0.0.1:0" . parse :: < SocketAddr > ( ) . unwrap ( ) . into ( ) ) . unwrap ( ) ;
715717 socket. listen ( 128 ) . unwrap ( ) ;
716718
717719 let addr = socket. local_addr ( ) . unwrap ( ) ;
0 commit comments