Skip to content

Commit f9a4b4d

Browse files
BerrysoftDetegr
authored andcommitted
Use ? instead of and_then
1 parent 3e5af79 commit f9a4b4d

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/platform/unix/mod.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,17 @@ fn pipe2(flags: nix::fcntl::OFlag) -> nix::Result<(RawFd, RawFd)> {
4242

4343
let pipe = unistd::pipe()?;
4444

45-
let mut res = Ok(0);
46-
4745
if flags.contains(OFlag::O_CLOEXEC) {
48-
res = res
49-
.and_then(|_| fcntl(&pipe.0, FcntlArg::F_SETFD(FdFlag::FD_CLOEXEC)))
50-
.and_then(|_| fcntl(&pipe.1, FcntlArg::F_SETFD(FdFlag::FD_CLOEXEC)));
46+
fcntl(&pipe.0, FcntlArg::F_SETFD(FdFlag::FD_CLOEXEC))?;
47+
fcntl(&pipe.1, FcntlArg::F_SETFD(FdFlag::FD_CLOEXEC))?;
5148
}
5249

5350
if flags.contains(OFlag::O_NONBLOCK) {
54-
res = res
55-
.and_then(|_| fcntl(&pipe.0, FcntlArg::F_SETFL(OFlag::O_NONBLOCK)))
56-
.and_then(|_| fcntl(&pipe.1, FcntlArg::F_SETFL(OFlag::O_NONBLOCK)));
51+
fcntl(&pipe.0, FcntlArg::F_SETFL(OFlag::O_NONBLOCK))?;
52+
fcntl(&pipe.1, FcntlArg::F_SETFL(OFlag::O_NONBLOCK))?;
5753
}
5854

59-
let pipe = (pipe.0.into_raw_fd(), pipe.1.into_raw_fd());
60-
61-
match res {
62-
Ok(_) => Ok(pipe),
63-
Err(e) => {
64-
let _ = unistd::close(pipe.0);
65-
let _ = unistd::close(pipe.1);
66-
Err(e)
67-
}
68-
}
55+
Ok((pipe.0.into_raw_fd(), pipe.1.into_raw_fd()))
6956
}
7057

7158
#[inline]
@@ -104,7 +91,10 @@ pub unsafe fn init_os_handler(overwrite: bool) -> Result<(), Error> {
10491
};
10592

10693
// Make sure we never block on write in the os handler.
107-
if let Err(e) = fcntl::fcntl(BorrowedFd::borrow_raw(PIPE.1), fcntl::FcntlArg::F_SETFL(fcntl::OFlag::O_NONBLOCK)) {
94+
if let Err(e) = fcntl::fcntl(
95+
BorrowedFd::borrow_raw(PIPE.1),
96+
fcntl::FcntlArg::F_SETFL(fcntl::OFlag::O_NONBLOCK),
97+
) {
10898
return Err(close_pipe(e));
10999
}
110100

0 commit comments

Comments
 (0)