From e0337dbbb0a919d2bff3c22b90d0f0f17bad775d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 29 Dec 2021 14:39:53 -0500 Subject: simplify --- src/command.rs | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) (limited to 'src/command.rs') diff --git a/src/command.rs b/src/command.rs index ef156aa..18e1f17 100644 --- a/src/command.rs +++ b/src/command.rs @@ -95,9 +95,12 @@ impl Command { self } - pub fn spawn(&mut self, pty: crate::Pty) -> crate::Result { + pub fn spawn( + &mut self, + pty: &crate::Pty, + ) -> crate::Result { let (stdin, stdout, stderr, pre_exec) = - crate::sys::setup_subprocess(&pty, pty.pts()?)?; + crate::sys::setup_subprocess(pty, pty.pts()?)?; self.inner.stdin(self.stdin.take().unwrap_or(stdin)); self.inner.stdout(self.stdout.take().unwrap_or(stdout)); @@ -108,43 +111,6 @@ impl Command { // async-signal-safe). unsafe { self.inner.pre_exec(pre_exec) }; - let child = self.inner.spawn()?; - - Ok(Child::new(child, pty)) - } -} - -pub struct Child { - inner: async_process::Child, - pty: crate::Pty, -} - -impl Child { - fn new(inner: async_process::Child, pty: crate::Pty) -> Self { - Self { inner, pty } - } - - #[must_use] - pub fn pty(&self) -> &crate::Pty { - &self.pty - } - - #[must_use] - pub fn pty_mut(&mut self) -> &mut crate::Pty { - &mut self.pty - } -} - -impl std::ops::Deref for Child { - type Target = async_process::Child; - - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl std::ops::DerefMut for Child { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.inner + Ok(self.inner.spawn()?) } } -- cgit v1.2.3-54-g00ecf