From e6a3feb286ed68876a7c9fd9162266f741ca1a32 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 23 Feb 2021 01:22:49 -0500 Subject: add async implementations of the pty itself --- src/pty.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/pty.rs') diff --git a/src/pty.rs b/src/pty.rs index f192298..b017225 100644 --- a/src/pty.rs +++ b/src/pty.rs @@ -1,6 +1,6 @@ use crate::error::*; -use ::std::os::unix::io::{AsRawFd as _, IntoRawFd as _}; +use ::std::os::unix::io::IntoRawFd as _; pub mod std; @@ -10,14 +10,14 @@ pub mod async_io; pub mod tokio; pub trait Pty { + type Pt; + fn new() -> Result where Self: Sized; - fn pt(&self) -> &::std::fs::File; + fn pt(&self) -> &Self::Pt; fn pts(&self) -> Result<::std::fs::File>; - fn resize(&self, size: &super::Size) -> Result<()> { - set_term_size(self.pt(), size).map_err(Error::SetTermSize) - } + fn resize(&self, size: &super::Size) -> Result<()>; } pub struct Size { @@ -84,9 +84,11 @@ nix::ioctl_write_ptr_bad!( nix::pty::Winsize ); -fn set_term_size(file: &::std::fs::File, size: &Size) -> nix::Result<()> { +fn set_term_size( + fd: ::std::os::unix::io::RawFd, + size: &Size, +) -> nix::Result<()> { let size = size.into(); - let fd = file.as_raw_fd(); // safe because std::fs::File is required to contain a valid file // 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 -- cgit v1.2.3-54-g00ecf