@@ -136,8 +136,9 @@ impl TcpStream {
136
136
/// a result of setting this option. For example Unix typically returns an
137
137
/// error of the kind `WouldBlock`, but Windows may return `TimedOut`.
138
138
#[ stable( feature = "socket_timeout" , since = "1.4.0" ) ]
139
- pub fn set_read_timeout ( & self , dur : Option < Duration > ) -> io:: Result < ( ) > {
140
- self . 0 . set_read_timeout ( dur)
139
+ pub fn set_read_timeout < D > ( & self , dur : D ) -> io:: Result < ( ) >
140
+ where D : Into < Option < Duration > > {
141
+ self . 0 . set_read_timeout ( dur. into ( ) )
141
142
}
142
143
143
144
/// Sets the write timeout to the timeout specified.
@@ -152,8 +153,9 @@ impl TcpStream {
152
153
/// as a result of setting this option. For example Unix typically returns
153
154
/// an error of the kind `WouldBlock`, but Windows may return `TimedOut`.
154
155
#[ stable( feature = "socket_timeout" , since = "1.4.0" ) ]
155
- pub fn set_write_timeout ( & self , dur : Option < Duration > ) -> io:: Result < ( ) > {
156
- self . 0 . set_write_timeout ( dur)
156
+ pub fn set_write_timeout < D > ( & self , dur : D ) -> io:: Result < ( ) >
157
+ where D : Into < Option < Duration > > {
158
+ self . 0 . set_write_timeout ( dur. into ( ) )
157
159
}
158
160
159
161
/// Returns the read timeout of this socket.
@@ -1059,12 +1061,12 @@ mod tests {
1059
1061
1060
1062
assert_eq ! ( None , t!( stream. read_timeout( ) ) ) ;
1061
1063
1062
- t ! ( stream. set_read_timeout( Some ( dur) ) ) ;
1064
+ t ! ( stream. set_read_timeout( dur) ) ;
1063
1065
assert_eq ! ( Some ( dur) , t!( stream. read_timeout( ) ) ) ;
1064
1066
1065
1067
assert_eq ! ( None , t!( stream. write_timeout( ) ) ) ;
1066
1068
1067
- t ! ( stream. set_write_timeout( Some ( dur) ) ) ;
1069
+ t ! ( stream. set_write_timeout( dur) ) ;
1068
1070
assert_eq ! ( Some ( dur) , t!( stream. write_timeout( ) ) ) ;
1069
1071
1070
1072
t ! ( stream. set_read_timeout( None ) ) ;
@@ -1081,7 +1083,7 @@ mod tests {
1081
1083
let listener = t ! ( TcpListener :: bind( & addr) ) ;
1082
1084
1083
1085
let mut stream = t ! ( TcpStream :: connect( & ( "localhost" , addr. port( ) ) ) ) ;
1084
- t ! ( stream. set_read_timeout( Some ( Duration :: from_millis( 1000 ) ) ) ) ;
1086
+ t ! ( stream. set_read_timeout( Duration :: from_millis( 1000 ) ) ) ;
1085
1087
1086
1088
let mut buf = [ 0 ; 10 ] ;
1087
1089
let start = Instant :: now ( ) ;
@@ -1097,7 +1099,7 @@ mod tests {
1097
1099
let listener = t ! ( TcpListener :: bind( & addr) ) ;
1098
1100
1099
1101
let mut stream = t ! ( TcpStream :: connect( & ( "localhost" , addr. port( ) ) ) ) ;
1100
- t ! ( stream. set_read_timeout( Some ( Duration :: from_millis( 1000 ) ) ) ) ;
1102
+ t ! ( stream. set_read_timeout( Duration :: from_millis( 1000 ) ) ) ;
1101
1103
1102
1104
let mut other_end = t ! ( listener. accept( ) ) . 0 ;
1103
1105
t ! ( other_end. write_all( b"hello world" ) ) ;
0 commit comments