aboutsummaryrefslogtreecommitdiffstats
path: root/src/pty.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-14 17:30:42 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-14 17:30:42 -0500
commit826f85eeed936137a0535a217df03e0fa7bc84f7 (patch)
treea042184c56b12b1010ef3263f5a7255bec032d67 /src/pty.rs
parent491ad3de31067cc8cafc540cea2c8891f2985815 (diff)
downloadpty-process-826f85eeed936137a0535a217df03e0fa7bc84f7.tar.gz
pty-process-826f85eeed936137a0535a217df03e0fa7bc84f7.zip
clippy
Diffstat (limited to 'src/pty.rs')
-rw-r--r--src/pty.rs30
1 files changed, 18 insertions, 12 deletions
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<Self>
+ fn new() -> crate::error::Result<Self>
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(|_| ())
}