File tree Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ impl Socket {
135
135
/// This function corresponds to `socket(2)` on Unix and `WSASocketW` on
136
136
/// Windows and simply creates a new socket, no other configuration is done.
137
137
pub fn new_raw ( domain : Domain , ty : Type , protocol : Option < Protocol > ) -> io:: Result < Socket > {
138
- let protocol = protocol. map ( |p| p. 0 ) . unwrap_or ( 0 ) ;
138
+ let protocol = protocol. map_or ( 0 , |p| p. 0 ) ;
139
139
sys:: socket ( domain. 0 , ty. 0 , protocol) . map ( Socket :: from_raw)
140
140
}
141
141
@@ -170,7 +170,7 @@ impl Socket {
170
170
ty : Type ,
171
171
protocol : Option < Protocol > ,
172
172
) -> io:: Result < ( Socket , Socket ) > {
173
- let protocol = protocol. map ( |p| p. 0 ) . unwrap_or ( 0 ) ;
173
+ let protocol = protocol. map_or ( 0 , |p| p. 0 ) ;
174
174
sys:: socketpair ( domain. 0 , ty. 0 , protocol)
175
175
. map ( |[ a, b] | ( Socket :: from_raw ( a) , Socket :: from_raw ( b) ) )
176
176
}
Original file line number Diff line number Diff line change @@ -1552,7 +1552,7 @@ impl crate::Socket {
1552
1552
#[ cfg( all( feature = "all" , target_vendor = "apple" ) ) ]
1553
1553
#[ cfg_attr( docsrs, doc( cfg( all( feature = "all" , target_vendor = "apple" ) ) ) ) ]
1554
1554
pub fn bind_device_by_index ( & self , interface : Option < NonZeroU32 > ) -> io:: Result < ( ) > {
1555
- let index = interface. map ( NonZeroU32 :: get) . unwrap_or ( 0 ) ;
1555
+ let index = interface. map_or ( 0 , NonZeroU32 :: get) ;
1556
1556
unsafe { setsockopt ( self . as_raw ( ) , IPPROTO_IP , libc:: IP_BOUND_IF , index) }
1557
1557
}
1558
1558
@@ -1908,9 +1908,9 @@ impl crate::Socket {
1908
1908
) ) )
1909
1909
) ]
1910
1910
pub fn set_tcp_user_timeout ( & self , timeout : Option < Duration > ) -> io:: Result < ( ) > {
1911
- let timeout = timeout
1912
- . map ( |to| min ( to. as_millis ( ) , libc:: c_uint:: MAX as u128 ) as libc:: c_uint )
1913
- . unwrap_or ( 0 ) ;
1911
+ let timeout = timeout. map_or ( 0 , |to| {
1912
+ min ( to. as_millis ( ) , libc:: c_uint:: MAX as u128 ) as libc:: c_uint
1913
+ } ) ;
1914
1914
unsafe {
1915
1915
setsockopt (
1916
1916
self . as_raw ( ) ,
Original file line number Diff line number Diff line change @@ -638,9 +638,9 @@ fn into_ms(duration: Option<Duration>) -> u32 {
638
638
// * Nanosecond precision is rounded up
639
639
// * Greater than u32::MAX milliseconds (50 days) is rounded up to
640
640
// INFINITE (never time out).
641
- duration
642
- . map ( |duration| min ( duration. as_millis ( ) , INFINITE as u128 ) as u32 )
643
- . unwrap_or ( 0 )
641
+ duration. map_or ( 0 , |duration| {
642
+ min ( duration. as_millis ( ) , INFINITE as u128 ) as u32
643
+ } )
644
644
}
645
645
646
646
pub ( crate ) fn set_tcp_keepalive ( socket : Socket , keepalive : & TcpKeepalive ) -> io:: Result < ( ) > {
You can’t perform that action at this time.
0 commit comments