From 826f85eeed936137a0535a217df03e0fa7bc84f7 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 14 Dec 2021 17:30:42 -0500 Subject: clippy --- src/pty.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/pty.rs') diff --git a/src/pty.rs b/src/pty.rs index bf34d61..fde86b1 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -1,5 +1,3 @@ -use crate::error::*; - use ::std::os::unix::io::IntoRawFd as _; #[cfg(any(feature = "backend-async-std", feature = "backend-smol"))] @@ -12,13 +10,13 @@ pub mod tokio; pub trait Pty { type Pt; - fn new() -> Result + fn new() -> crate::error::Result where Self: Sized; fn pt(&self) -> &Self::Pt; fn pt_mut(&mut self) -> &mut Self::Pt; - fn pts(&self) -> Result<::std::fs::File>; - fn resize(&self, size: &super::Size) -> Result<()>; + fn pts(&self) -> crate::error::Result<::std::fs::File>; + fn resize(&self, size: &super::Size) -> crate::error::Result<()>; } /// Represents the size of the pty. @@ -32,6 +30,7 @@ pub struct Size { impl Size { /// Returns a [`Size`](Size) instance with the given number of rows and /// columns. + #[must_use] pub fn new(row: u16, col: u16) -> Self { Self { row, @@ -43,6 +42,7 @@ impl Size { /// Returns a [`Size`](Size) instance with the given number of rows and /// columns, as well as the given pixel dimensions. + #[must_use] pub fn new_with_pixel( row: u16, col: u16, @@ -69,15 +69,19 @@ impl From<&Size> for nix::pty::Winsize { } } -fn create_pt() -> Result<(::std::os::unix::io::RawFd, ::std::path::PathBuf)> { +fn create_pt( +) -> crate::error::Result<(::std::os::unix::io::RawFd, ::std::path::PathBuf)> +{ let pt = nix::pty::posix_openpt( nix::fcntl::OFlag::O_RDWR | nix::fcntl::OFlag::O_NOCTTY, ) - .map_err(Error::CreatePty)?; - nix::pty::grantpt(&pt).map_err(Error::CreatePty)?; - nix::pty::unlockpt(&pt).map_err(Error::CreatePty)?; + .map_err(crate::error::Error::CreatePty)?; + nix::pty::grantpt(&pt).map_err(crate::error::Error::CreatePty)?; + nix::pty::unlockpt(&pt).map_err(crate::error::Error::CreatePty)?; - let ptsname = nix::pty::ptsname_r(&pt).map_err(Error::CreatePty)?.into(); + let ptsname = nix::pty::ptsname_r(&pt) + .map_err(crate::error::Error::CreatePty)? + .into(); let pt_fd = pt.into_raw_fd(); @@ -99,6 +103,8 @@ fn set_term_size( // descriptor and size is guaranteed to be initialized because it's a // normal rust value, and nix::pty::Winsize is a repr(C) struct with the // same layout as `struct winsize` from sys/ioctl.h. - unsafe { set_term_size_unsafe(fd, &size as *const nix::pty::Winsize) } - .map(|_| ()) + unsafe { + set_term_size_unsafe(fd, ::std::ptr::NonNull::from(&size).as_ptr()) + } + .map(|_| ()) } -- cgit v1.2.3-54-g00ecf