diff --git a/src/backend/libc/io/errno.rs b/src/backend/libc/io/errno.rs index 81f0e4893..87926d03d 100644 --- a/src/backend/libc/io/errno.rs +++ b/src/backend/libc/io/errno.rs @@ -1093,7 +1093,8 @@ impl Errno { pub fn from_io_error(io_err: &std::io::Error) -> Option { io_err .raw_os_error() - .and_then(|raw| if raw != 0 { Some(Self(raw)) } else { None }) + .filter(|&raw| raw != 0) + .map(Self) } /// Extract the raw OS error number from this error. diff --git a/src/backend/libc/net/addr.rs b/src/backend/libc/net/addr.rs index 1699ffa99..8074941c5 100644 --- a/src/backend/libc/net/addr.rs +++ b/src/backend/libc/net/addr.rs @@ -223,13 +223,13 @@ impl SocketAddrUnix { #[inline] fn bytes(&self) -> Option<&[u8]> { - let len = self.len(); - if len != 0 { - let bytes = &self.unix.sun_path[..len - offsetof_sun_path()]; - // SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`. - Some(unsafe { slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len()) }) - } else { - None + match self.len() { + 0 => None, + len => { + let bytes = &self.unix.sun_path[..len - offsetof_sun_path()]; + // SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`. + Some(unsafe { slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len()) }) + } } } } diff --git a/src/net/socket_addr_any.rs b/src/net/socket_addr_any.rs index 7a9530444..bbe258bdc 100644 --- a/src/net/socket_addr_any.rs +++ b/src/net/socket_addr_any.rs @@ -55,11 +55,8 @@ impl SocketAddrBuf { #[inline] pub(crate) unsafe fn into_any_option(self) -> Option { let len = bitcast!(self.len); - if read_sockaddr::sockaddr_nonempty(self.storage.as_ptr().cast(), len) { - Some(SocketAddrAny::new(self.storage, len)) - } else { - None - } + read_sockaddr::sockaddr_nonempty(self.storage.as_ptr().cast(), len) + .then(|| SocketAddrAny::new(self.storage, len)) } } diff --git a/src/process/wait.rs b/src/process/wait.rs index 0e004f3d2..5878fa519 100644 --- a/src/process/wait.rs +++ b/src/process/wait.rs @@ -125,11 +125,8 @@ impl WaitStatus { #[inline] #[doc(alias = "WSTOPSIG")] pub fn stopping_signal(self) -> Option { - if self.stopped() { - Some(backend::process::wait::WSTOPSIG(self.0)) - } else { - None - } + self.stopped() + .then(|| backend::process::wait::WSTOPSIG(self.0)) } /// Returns the exit status number returned by the process, if it exited @@ -137,11 +134,8 @@ impl WaitStatus { #[inline] #[doc(alias = "WEXITSTATUS")] pub fn exit_status(self) -> Option { - if self.exited() { - Some(backend::process::wait::WEXITSTATUS(self.0)) - } else { - None - } + self.exited() + .then(|| backend::process::wait::WEXITSTATUS(self.0)) } /// Returns the number of the signal that terminated the process, if the @@ -149,11 +143,8 @@ impl WaitStatus { #[inline] #[doc(alias = "WTERMSIG")] pub fn terminating_signal(self) -> Option { - if self.signaled() { - Some(backend::process::wait::WTERMSIG(self.0)) - } else { - None - } + self.signaled() + .then(|| backend::process::wait::WTERMSIG(self.0)) } } @@ -247,11 +238,7 @@ impl WaitIdStatus { #[inline] #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn stopping_signal(&self) -> Option { - if self.stopped() { - Some(self.si_status()) - } else { - None - } + self.stopped().then(|| self.si_status()) } /// Returns the number of the signal that trapped the process, if the @@ -259,11 +246,7 @@ impl WaitIdStatus { #[inline] #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn trapping_signal(&self) -> Option { - if self.trapped() { - Some(self.si_status()) - } else { - None - } + self.trapped().then(|| self.si_status()) } /// Returns the exit status number returned by the process, if it exited @@ -271,11 +254,7 @@ impl WaitIdStatus { #[inline] #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn exit_status(&self) -> Option { - if self.exited() { - Some(self.si_status()) - } else { - None - } + self.exited().then(|| self.si_status()) } /// Returns the number of the signal that terminated the process, if the @@ -283,11 +262,7 @@ impl WaitIdStatus { #[inline] #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia", target_os = "netbsd")))] pub fn terminating_signal(&self) -> Option { - if self.killed() || self.dumped() { - Some(self.si_status()) - } else { - None - } + (self.killed() || self.dumped()).then(|| self.si_status()) } /// Return the raw `si_signo` value returned from `waitid`.