From 0fb3a12139b5f79726da737b42b3cca9825607f5 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Wed, 7 Dec 2022 17:13:26 +0800 Subject: [PATCH] fmt & clippy --- src/pty.rs | 2 +- src/sys/termios.rs | 31 +++++++++++++++++++++++++------ test/sys/test_termios.rs | 11 +++-------- test/test_pty.rs | 3 +-- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/pty.rs b/src/pty.rs index b63e3f7afa..2866c6df48 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -144,7 +144,7 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result { return Err(Errno::last()); } - Ok(PtyMaster(unsafe {OwnedFd::from_raw_fd(fd) })) + Ok(PtyMaster(unsafe { OwnedFd::from_raw_fd(fd) })) } /// Get the name of the slave pseudoterminal (see diff --git a/src/sys/termios.rs b/src/sys/termios.rs index 337621767a..4cc635bc21 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -1146,7 +1146,9 @@ pub fn cfmakesane(termios: &mut Termios) { pub fn tcgetattr(fd: &Fd) -> Result { let mut termios = mem::MaybeUninit::uninit(); - let res = unsafe { libc::tcgetattr(fd.as_fd().as_raw_fd(), termios.as_mut_ptr()) }; + let res = unsafe { + libc::tcgetattr(fd.as_fd().as_raw_fd(), termios.as_mut_ptr()) + }; Errno::result(res)?; @@ -1159,10 +1161,18 @@ pub fn tcgetattr(fd: &Fd) -> Result { /// `tcsetattr()` reconfigures the given port based on a given `Termios` structure. This change /// takes affect at a time specified by `actions`. Note that this function may return success if /// *any* of the parameters were successfully set, not only if all were set successfully. -pub fn tcsetattr(fd: &Fd, actions: SetArg, termios: &Termios) -> Result<()> { +pub fn tcsetattr( + fd: &Fd, + actions: SetArg, + termios: &Termios, +) -> Result<()> { let inner_termios = termios.get_libc_termios(); Errno::result(unsafe { - libc::tcsetattr(fd.as_fd().as_raw_fd(), actions as c_int, &*inner_termios) + libc::tcsetattr( + fd.as_fd().as_raw_fd(), + actions as c_int, + &*inner_termios, + ) }) .map(drop) } @@ -1179,7 +1189,10 @@ pub fn tcdrain(fd: &Fd) -> Result<()> { /// `tcflow()` suspends of resumes the transmission or reception of data for the given port /// depending on the value of `action`. pub fn tcflow(fd: &Fd, action: FlowArg) -> Result<()> { - Errno::result(unsafe { libc::tcflow(fd.as_fd().as_raw_fd(), action as c_int) }).map(drop) + Errno::result(unsafe { + libc::tcflow(fd.as_fd().as_raw_fd(), action as c_int) + }) + .map(drop) } /// Discard data in the output or input queue (see @@ -1188,7 +1201,10 @@ pub fn tcflow(fd: &Fd, action: FlowArg) -> Result<()> { /// `tcflush()` will discard data for a terminal port in the input queue, output queue, or both /// depending on the value of `action`. pub fn tcflush(fd: &Fd, action: FlushArg) -> Result<()> { - Errno::result(unsafe { libc::tcflush(fd.as_fd().as_raw_fd(), action as c_int) }).map(drop) + Errno::result(unsafe { + libc::tcflush(fd.as_fd().as_raw_fd(), action as c_int) + }) + .map(drop) } /// Send a break for a specific duration (see @@ -1197,7 +1213,10 @@ pub fn tcflush(fd: &Fd, action: FlushArg) -> Result<()> { /// When using asynchronous data transmission `tcsendbreak()` will transmit a continuous stream /// of zero-valued bits for an implementation-defined duration. pub fn tcsendbreak(fd: &Fd, duration: c_int) -> Result<()> { - Errno::result(unsafe { libc::tcsendbreak(fd.as_fd().as_raw_fd(), duration) }).map(drop) + Errno::result(unsafe { + libc::tcsendbreak(fd.as_fd().as_raw_fd(), duration) + }) + .map(drop) } feature! { diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs index 0fc12af1ab..cf55b10cd8 100644 --- a/test/sys/test_termios.rs +++ b/test/sys/test_termios.rs @@ -29,10 +29,7 @@ fn test_tcgetattr_pty() { #[test] fn test_tcgetattr_enotty() { let file = tempfile().unwrap(); - assert_eq!( - termios::tcgetattr(&file).err(), - Some(Errno::ENOTTY) - ); + assert_eq!(termios::tcgetattr(&file).err(), Some(Errno::ENOTTY)); } // Test modifying output flags @@ -44,8 +41,7 @@ fn test_output_flags() { // Open one pty to get attributes for the second one let mut termios = { let pty = openpty(None, None).expect("openpty failed"); - let termios = tcgetattr(&pty.slave).expect("tcgetattr failed"); - termios + tcgetattr(&pty.slave).expect("tcgetattr failed") }; // Make sure postprocessing '\r' isn't specified by default or this test is useless. @@ -82,8 +78,7 @@ fn test_local_flags() { // Open one pty to get attributes for the second one let mut termios = { let pty = openpty(None, None).unwrap(); - let termios = tcgetattr(&pty.slave).unwrap(); - termios + tcgetattr(&pty.slave).unwrap() }; // Make sure echo is specified by default or this test is useless. diff --git a/test/test_pty.rs b/test/test_pty.rs index 485c44eea5..e1286e553c 100644 --- a/test/test_pty.rs +++ b/test/test_pty.rs @@ -213,8 +213,7 @@ fn test_openpty_with_termios() { // Open one pty to get attributes for the second one let mut termios = { let pty = openpty(None, None).unwrap(); - let termios = tcgetattr(&pty.slave).unwrap(); - termios + tcgetattr(&pty.slave).unwrap() }; // Make sure newlines are not transformed so the data is preserved when sent. termios.output_flags.remove(OutputFlags::ONLCR);