Skip to content

Commit 938d6bd

Browse files
committed
Use map_or where appropriate
As recommended by Clippy.
1 parent c8118e4 commit 938d6bd

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/socket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl Socket {
135135
/// This function corresponds to `socket(2)` on Unix and `WSASocketW` on
136136
/// Windows and simply creates a new socket, no other configuration is done.
137137
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);
139139
sys::socket(domain.0, ty.0, protocol).map(Socket::from_raw)
140140
}
141141

@@ -170,7 +170,7 @@ impl Socket {
170170
ty: Type,
171171
protocol: Option<Protocol>,
172172
) -> 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);
174174
sys::socketpair(domain.0, ty.0, protocol)
175175
.map(|[a, b]| (Socket::from_raw(a), Socket::from_raw(b)))
176176
}

src/sys/unix.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ impl crate::Socket {
15521552
#[cfg(all(feature = "all", target_vendor = "apple"))]
15531553
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_vendor = "apple"))))]
15541554
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);
15561556
unsafe { setsockopt(self.as_raw(), IPPROTO_IP, libc::IP_BOUND_IF, index) }
15571557
}
15581558

@@ -1908,9 +1908,9 @@ impl crate::Socket {
19081908
)))
19091909
)]
19101910
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+
});
19141914
unsafe {
19151915
setsockopt(
19161916
self.as_raw(),

src/sys/windows.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,9 @@ fn into_ms(duration: Option<Duration>) -> u32 {
638638
// * Nanosecond precision is rounded up
639639
// * Greater than u32::MAX milliseconds (50 days) is rounded up to
640640
// 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+
})
644644
}
645645

646646
pub(crate) fn set_tcp_keepalive(socket: Socket, keepalive: &TcpKeepalive) -> io::Result<()> {

0 commit comments

Comments
 (0)